{"id":26127726,"url":"https://github.com/dylibso/mcpx-openai-node","last_synced_at":"2025-04-13T17:22:54.156Z","repository":{"id":271416191,"uuid":"911747738","full_name":"dylibso/mcpx-openai-node","owner":"dylibso","description":"OpenAI node support for MCPX","archived":false,"fork":false,"pushed_at":"2025-04-08T17:09:51.000Z","size":158,"stargazers_count":13,"open_issues_count":5,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-08T17:31:41.589Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dylibso.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-03T18:47:48.000Z","updated_at":"2025-04-07T23:06:51.000Z","dependencies_parsed_at":"2025-01-07T16:24:57.197Z","dependency_job_id":"c676221d-35f8-40e5-b79b-cb1c680f7d1d","html_url":"https://github.com/dylibso/mcpx-openai-node","commit_stats":null,"previous_names":["dylibso/mcpx-openai-node"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dylibso%2Fmcpx-openai-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dylibso%2Fmcpx-openai-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dylibso%2Fmcpx-openai-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dylibso%2Fmcpx-openai-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dylibso","download_url":"https://codeload.github.com/dylibso/mcpx-openai-node/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248750872,"owners_count":21155797,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-10T18:36:16.526Z","updated_at":"2025-04-13T17:22:54.134Z","avatar_url":"https://github.com/dylibso.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MCPX OpenAI Client\n\nThis library allows you connect your [OpenAI](https://openai.com) models to\n[mcp.run](https://mcp.run) and expose your installed servlets as tools which can be \ninvoked in process (without spinning up many server processes).\n\nIt accomplishes this by bundling an [MCP](https://modelcontextprotocol.io/introduction)\nclient, server, and our [wasm technology](https://www.getxtp.com/).\n\n## Usage\n\n### Install\n\nYou just need the mcpx-openai library and the openai library (if you don't already have it).\n\n```\nnpm install @dylibso/mcpx-openai openai --save\n```\n\nTo get an mcp.run session id, run this command and follow the instructions:\n\n```\nnpx --yes -p @dylibso/mcpx@latest gen-session\n```\n\n### Code\n\nMcpxOpenAI presents as a wrapper around the [OpenAI Node](https://github.com/openai/openai-node) library.\n\n```typescript\nimport OpenAI from \"openai\";\nimport McpxOpenAI from \"@dylibso/mcpx-openai\"\n\nasync function main() {\n    // Create your OpenAI client as normal\n    const openai = new OpenAI({\n      apiKey: String(process.env['OPENAI_API_KEY']),\n    })\n\n    const sessionId = String(process.env['MCP_RUN_SESSION_ID'])\n\n    // Wrap with McpxOpenAI\n    const mcpx = await McpxOpenAI.create({\n        openai,\n        sessionId,\n    })\n\n    // NOTE: consider writing a system message to guide the agent into\n    // getting the behavior you want for more complex scenarios\n    const messages = [];\n\n    // call any tool compatible api, e.g chat completion:\n    // let's ask it to evalute some javascript. If you have\n    // this tool installed: https://www.mcp.run/bhelx/eval-js it should\n    // determine and use this to evaluate it in a sandbox\n    messages.push({\n      role: 'user',\n      content: `\n          Write a djb2hash function in javascript and evalute it on the string \"Hello, World!\"\n      `\n    })\n\n    // this will automatically process all tool calls\n    // until there are none left\n    let response = await mcpx.chatCompletionCreate({\n      model: 'gpt-4o',\n      temperature: 0,\n      messages,\n    });\n\n    console.log(response.choices[0]?.message)\n    //=\u003e The DJB2 hash of the string \"Hello, World!\" is `-1763540338`.\n}\n\nmain()\n```\n\n### Examples\n\n* [Example chat application](examples/chat)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdylibso%2Fmcpx-openai-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdylibso%2Fmcpx-openai-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdylibso%2Fmcpx-openai-node/lists"}