{"_id":"@4ourlab/mcp-client-gpt","name":"@4ourlab/mcp-client-gpt","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@4ourlab/mcp-client-gpt","version":"1.0.0","description":"MCP (Model Context Protocol) implementation for OpenAI GPT models","main":"build/src/index.js","types":"build/src/index.d.ts","exports":{".":{"import":"./build/src/index.js","require":"./build/src/index.js"},"./examples/*":"./build/examples/*"},"scripts":{"build":"tsc && cp -r examples build/ && node -e \"require('fs').chmodSync('build/src/index.js', '755')\"","dev":"tsc --watch"},"keywords":["mcp","model-context-protocol","gpt","openai","ai","typescript","nodejs"],"author":{"name":"Billston"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/4ourlab/mcp-client-gpt.git"},"homepage":"https://github.com/4ourlab/mcp-client-gpt","bugs":{"url":"https://github.com/4ourlab/mcp-client-gpt/issues"},"dependencies":{"@modelcontextprotocol/sdk":"^1.17.0","openai":"^4.0.0"},"devDependencies":{"@types/node":"^22.16.5","typescript":"^5.8.3"},"_id":"@4ourlab/mcp-client-gpt@1.0.0","_nodeVersion":"22.15.0","_npmVersion":"11.4.2","dist":{"integrity":"sha512-CVVMlX1FMUxltCmc7rI42F7v3nYnGedXPXWht7RBm5knFLoyqs361qTXYUu0w1ZCfY8cgBGfkE6wXhLfgu7gYg==","shasum":"195019148efb18e1f1e3ee086ed03d17e91c6849","tarball":"https://registry.npmjs.org/@4ourlab/mcp-client-gpt/-/mcp-client-gpt-1.0.0.tgz","fileCount":18,"unpackedSize":26329,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCfybrExbbvg3mXi/SSkMlKaAXTF5x2x+vYTHk+W1PSNgIhAM+Ey7omjfhkOY8TjOandgaWnk9hikueyVKqESpYcj1y"}]},"_npmUser":{"name":"billston","email":"billston.apaza@gmail.com"},"directories":{},"maintainers":[{"name":"billston","email":"billston.apaza@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/mcp-client-gpt_1.0.0_1754931012811_0.17267357779894055"},"_hasShrinkwrap":false}},"time":{"created":"2025-08-11T16:50:12.709Z","1.0.0":"2025-08-11T16:50:12.994Z","modified":"2025-08-11T16:50:13.221Z"},"maintainers":[{"name":"billston","email":"billston.apaza@gmail.com"}],"description":"MCP (Model Context Protocol) implementation for OpenAI GPT models","homepage":"https://github.com/4ourlab/mcp-client-gpt","keywords":["mcp","model-context-protocol","gpt","openai","ai","typescript","nodejs"],"repository":{"type":"git","url":"git+https://github.com/4ourlab/mcp-client-gpt.git"},"author":{"name":"Billston"},"bugs":{"url":"https://github.com/4ourlab/mcp-client-gpt/issues"},"license":"MIT","readme":"# @4ourlab/mcp-client-gpt\n\nA MCP (Model Context Protocol) implementation for OpenAI GPT models that allows connecting and using multiple MCP servers through OpenAI's GPT API.\n\nThis implementation is based on the official [Model Context Protocol documentation](https://modelcontextprotocol.io/).\n\n## Features\n\n- 🔗 Connect to multiple MCP servers\n- 🤖 Integration with OpenAI GPT API\n- 📝 Support for custom system prompts\n- 🔧 Complete TypeScript interface\n- 🛠️ Included usage examples\n- ⚙️ Configurable token limits\n\n## Supported Models\n\nThis client has been tested with the following GPT models:\n- `gpt-5` (GPT-5)\n- `gpt-5-mini` (GPT-5 Mini)\n- `gpt-5-nano` (GPT-5 Nano)\n\n## Installation\n\n```bash\nnpm install @4ourlab/mcp-client-gpt\n```\n\n## Basic Usage\n\n```javascript\nimport { MCPClient } from '@4ourlab/mcp-client-gpt';\n\nconst mcpClient = new MCPClient(\n    \"your-openai-api-key\",\n    \"gpt-5\", // or any other supported model\n    1000, // maxOutputTokens\n    \"./examples/mcpServer.json\",\n    \"Optional system prompt\"\n);\n\ntry {\n    await mcpClient.connectToServers();\n    const response = await mcpClient.processQuery(\"Your query here\");\n    console.log(response);\n} finally {\n    await mcpClient.cleanup();\n}\n```\n\n## MCP Server Configuration\n\nCreate an `mcpServer.json` file with your server configuration:\n\n```json\n{\n    \"mcpServers\": {\n        \"weather\": {\n            \"command\": \"node\",\n            \"args\": [\"/path/to/mcpserver-weather/build/index.js\"]\n        },\n        \"mssql\": {\n            \"command\": \"dotnet\",\n            \"args\": [\"run\", \"--project\", \"/path/to/mcpserver-mssql.csproj\"]\n        }\n    }\n}\n```\n\n## Examples\n\n### Example 1: Interactive Chat\n\n```javascript\nimport { MCPClient } from '@4ourlab/mcp-client-gpt';\n\nasync function main() {\n    const mcpClient = new MCPClient(\n        \"your-openai-api-key\",\n        \"gpt-5\",\n        1000, // maxOutputTokens\n        \"./examples/mcpServer.json\",\n        \"\" // systemPrompt (optional)\n    );\n\n    try {\n        await mcpClient.connectToServers();\n        await mcpClient.chatLoop();\n    } finally {\n        await mcpClient.cleanup();\n        process.exit(0);\n    }\n}\n\nmain().catch(console.error);\n```\n\n### Example 2: Query Processing with JSON Response\n\n```javascript\nimport { MCPClient } from '@4ourlab/mcp-client-gpt';\n\nasync function main() {\n    const systemPrompt = `\n        You are an intelligent assistant with access to tools. Use your knowledge and available tools to solve problems proactively. \n\n        For final responses, use JSON format:\n        {\n            \"header\": {\n                \"success\": true|false,\n                \"usedTools\": true|false,\n                \"message\": \"error description when success=false\"\n            },\n            \"result\": {\n                \"your response content here\"\n            }\n        }`;\n\n    const mcpClient = new MCPClient(\n        \"your-openai-api-key\",\n        \"gpt-5\",\n        3000, // maxOutputTokens\n        \"./examples/mcpServer.json\",\n        systemPrompt\n    );\n\n    try {\n        await mcpClient.connectToServers();\n        const response = await mcpClient.processQuery(\"What's the weather in Sacramento?\");\n        console.log(\"\\nResponse:\\n\" + cleanResponse(response));\n    } catch (error) {\n        console.error(\"Error in main:\", error);\n    } finally {\n        await mcpClient.cleanup();\n        process.exit(0);\n    }\n}\n\nfunction cleanResponse(response) {\n    const content = response;\n    const json = content.match(/```json\\n([\\s\\S]*?)\\n```/)?.[1] || content.match(/\\{[\\s\\S]*\\}/)?.[0];\n    return json || response;\n}\n\nmain().catch(console.error);\n```\n\n## API\n\n### MCPClient\n\n#### Constructor\n```javascript\nnew MCPClient(\n    apiKey: string, \n    model: string, \n    maxOutputTokens: number, \n    serverConfigPath: string, \n    systemPrompt?: string\n)\n```\n\n**Parameters:**\n- `apiKey`: Your OpenAI API key\n- `model`: The GPT model to use (e.g., \"gpt-5\", \"gpt-5-mini\", \"gpt-5-nano\")\n- `maxOutputTokens`: Maximum number of tokens for the response\n- `serverConfigPath`: Path to the MCP server configuration JSON file\n- `systemPrompt`: Optional system prompt to guide the model's behavior\n\n#### Methods\n\n- `connectToServers()`: Connect to all configured MCP servers\n- `processQuery(query: string)`: Process a query using available servers\n- `chatLoop()`: Start an interactive chat loop\n- `cleanup()`: Clean up connections and resources\n\n## Dependencies\n\n- `openai`: Official OpenAI API client\n- `@modelcontextprotocol/sdk`: Official MCP SDK\n\n## Development\n\n### Building the project\n\n```bash\nnpm run build\n```\n\n### Development mode\n\n```bash\nnpm run dev\n```\n\n## License\n\nMIT ","readmeFilename":"README.md","_rev":"1-30f53fc52470db97bd19405f31f23a15"}