{"_id":"@agentpaid/mcp-use","_rev":"3-731904ce6f72cf153f5d4748070f0c68","name":"@agentpaid/mcp-use","dist-tags":{"latest":"0.1.9"},"versions":{"0.1.7":{"name":"@agentpaid/mcp-use","version":"0.1.7","keywords":["MCP","Model Context Protocol","LangChain","Zod","schema","SDK","eventsource","AI","utility","typescript"],"author":{"name":"Zane"},"license":"MIT","_id":"@agentpaid/mcp-use@0.1.7","maintainers":[{"name":"rdosanjh","email":"rdosanjh73@gmail.com"},{"name":"georgi-paid","email":"georgi@paid.ai"},{"name":"zhalyn","email":"zhalyn@paid.ai"}],"homepage":"https://github.com/mcp-use/mcp-use-ts#readme","bugs":{"url":"https://github.com/mcp-use/mcp-use-ts/issues"},"dist":{"shasum":"ad44344bb635200dbdca278f4bac9d70113769cb","tarball":"https://registry.npmjs.org/@agentpaid/mcp-use/-/mcp-use-0.1.7.tgz","fileCount":141,"integrity":"sha512-d0/5j2o9Ton9UkMmEMGOR63COrFiRxG4XSYquf6U85p7/du/EhwxyIGRj7pmqj1KmvlMAQVcVv3JbQN9PwSMVw==","signatures":[{"sig":"MEQCIG4CAZuhMR/3XJWAECZhh1ZjCaCqiteTbFryOhBqYT9BAiBVC9ub/3r8jTZ4RhA8yvHROldfHeUsJ/yFMk8dC86tKA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":235805},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=22.0.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"gitHead":"9718c8c9e51d1db626bfb4dced8c8ce88f03927d","scripts":{"fmt":"eslint --fix","lint":"eslint","build":"rm -rf dist && tsc","start":"node dist/index.js","watch":"tsc --watch","prepare":"husky","release":"npm version patch --tag-version-prefix=v && git push --follow-tags","lint:fix":"eslint --fix","example:chat":"npm run build && node dist/examples/chat_example.js","example:http":"npm run build && node dist/examples/http_example.js","example:multi":"npm run build && node dist/examples/multi_server_example.js","example:oauth":"npm run build && node dist/examples/simple_oauth_example.js","release:major":"npm version major --tag-version-prefix=v && git push --follow-tags","release:minor":"npm version minor --tag-version-prefix=v && git push --follow-tags","example:airbnb":"npm run build && node dist/examples/airbnb_use.js","prepublishOnly":"npm run build","example:blender":"npm run build && node dist/examples/blender_use.js","example:browser":"npm run build && node dist/examples/browser_use.js","example:sandbox":"npm run build && node dist/examples/sandbox_everything.js","example:add_server":"npm run build && node dist/examples/add_server_tool.js","example:everything":"npm run build && node dist/examples/mcp_everything.js","example:filesystem":"npm run build && node dist/examples/filesystem_use.js"},"_npmUser":{"name":"rdosanjh","email":"rdosanjh73@gmail.com"},"repository":{"url":"git+https://github.com/mcp-use/mcp-use-ts.git","type":"git"},"_npmVersion":"10.9.2","description":"A utility library for integrating Model Context Protocol (MCP) with LangChain, Zod, and related tools. Provides helpers for schema conversion, event streaming, and SDK usage.","directories":{},"lint-staged":{"**/*.ts":["npm run build"],"*.{js,ts}":["npm run lint"]},"_nodeVersion":"23.6.0","dependencies":{"ws":"^8.18.2","zod":"^3.25.48","uuid":"^11.1.0","dotenv":"^16.5.0","winston":"^3.17.0","fastembed":"^1.14.4","langchain":"^0.3.27","lodash-es":"^4.17.21","eventsource":"^3.0.6","@scarf/scarf":"^1.4.0","posthog-node":"^5.1.1","@langchain/core":"0.3.58","@langchain/openai":"^0.5.15","zod-to-json-schema":"^3.24.5","@langchain/anthropic":"^0.3.14","@modelcontextprotocol/sdk":"1.12.1","@dmitryrechkin/json-schema-to-zod":"^1.0.1"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org"},"_hasShrinkwrap":false,"packageManager":"pnpm@10.6.1","devDependencies":{"shx":"^0.4.0","husky":"^9.1.7","eslint":"^9.28.0","@types/ws":"^8.18.1","typescript":"^5.8.3","lint-staged":"^15.2.11","@types/lodash-es":"^4.17.12","@antfu/eslint-config":"^4.13.2","eslint-plugin-format":"^1.0.1"},"_npmOperationalInternal":{"tmp":"tmp/mcp-use_0.1.7_1752831418847_0.0864820653062286","host":"s3://npm-registry-packages-npm-production"}},"0.1.8":{"name":"@agentpaid/mcp-use","version":"0.1.8","keywords":["MCP","Model Context Protocol","LangChain","Zod","schema","SDK","eventsource","AI","utility","typescript"],"author":{"name":"Zane"},"license":"MIT","_id":"@agentpaid/mcp-use@0.1.8","maintainers":[{"name":"rdosanjh","email":"rdosanjh73@gmail.com"},{"name":"georgi-paid","email":"georgi@paid.ai"},{"name":"zhalyn","email":"zhalyn@paid.ai"}],"homepage":"https://github.com/mcp-use/mcp-use-ts#readme","bugs":{"url":"https://github.com/mcp-use/mcp-use-ts/issues"},"dist":{"shasum":"8f701b1330e0b991f3a3f9ee11de4212679ce5f5","tarball":"https://registry.npmjs.org/@agentpaid/mcp-use/-/mcp-use-0.1.8.tgz","fileCount":123,"integrity":"sha512-F5RsTR++YqiWf3WwdMyJH9MZaXoi+p15fTtbjE9Gy24kHv7GNcJ1wJ4dqWCPR5envY7Wb/ZG2DBkQGSyIyT7lQ==","signatures":[{"sig":"MEQCIAzQMEsqnPMxo21F11WPahcGu8OBifIpILOZHp8f4G9YAiAEXsMKUxrX00eX3X6Uc1AcjrrkPlx5txAHwa3h9zsyYA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":234815},"main":"./dist-cjs/index.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=22.0.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist-cjs/index.js"}},"gitHead":"b49d2855058985091cb90eca22b28e3ebdb3415c","scripts":{"fmt":"eslint --fix","lint":"eslint","test":"vitest","build":"shx rm -rf dist && tsc","start":"node dist/index.js","watch":"tsc --watch","prepare":"husky","release":"npm version patch --tag-version-prefix=v && git push --follow-tags","lint:fix":"eslint --fix","test:run":"vitest run","build:all":"npm run build && npm run build:cjs","build:cjs":"shx rm -rf dist-cjs && tsc --project tsconfig.cjs.json && node scripts/create-cjs-package.cjs","test:simple":"vitest run tests/stream_events_simple.test.ts","example:chat":"npm run build && node dist/examples/chat_example.js","example:http":"npm run build && node dist/examples/http_example.js","example:multi":"npm run build && node dist/examples/multi_server_example.js","example:oauth":"npm run build && node dist/examples/simple_oauth_example.js","release:major":"npm version major --tag-version-prefix=v && git push --follow-tags","release:minor":"npm version minor --tag-version-prefix=v && git push --follow-tags","example:ai_sdk":"npm run build && node dist/examples/ai_sdk_example.js","example:airbnb":"npm run build && node dist/examples/airbnb_use.js","example:stream":"npm run build && node dist/examples/stream_example.js","prepublishOnly":"npm run build","example:blender":"npm run build && node dist/examples/blender_use.js","example:browser":"npm run build && node dist/examples/browser_use.js","example:sandbox":"npm run build && node dist/examples/sandbox_everything.js","test:integration":"vitest run tests/stream_events.test.ts","example:add_server":"npm run build && node dist/examples/add_server_tool.js","example:everything":"npm run build && node dist/examples/mcp_everything.js","example:filesystem":"npm run build && node dist/examples/filesystem_use.js","example:stream_events":"npm run build && node dist/examples/stream_events_example.js"},"_npmUser":{"name":"rdosanjh","email":"rdosanjh73@gmail.com"},"repository":{"url":"git+https://github.com/mcp-use/mcp-use-ts.git","type":"git"},"_npmVersion":"10.9.2","description":"A utility library for integrating Model Context Protocol (MCP) with LangChain, Zod, and related tools. Provides helpers for schema conversion, event streaming, and SDK usage.","directories":{},"lint-staged":{"**/*.ts":["npm run build"],"*.{js,ts}":["npm run lint"]},"_nodeVersion":"23.6.0","dependencies":{"ai":"^4.3.19","ws":"^8.18.2","zod":"^3.25.48","uuid":"^11.1.0","dotenv":"^16.5.0","lodash":"^4.17.21","winston":"^3.17.0","fastembed":"^1.14.4","langchain":"^0.3.27","lodash-es":"^4.17.21","eventsource":"^3.0.6","@scarf/scarf":"^1.4.0","posthog-node":"^5.1.1","@langchain/core":"0.3.58","@langchain/openai":"^0.5.15","zod-to-json-schema":"^3.24.5","@langchain/anthropic":"^0.3.14","@modelcontextprotocol/sdk":"1.12.1","@dmitryrechkin/json-schema-to-zod":"^1.0.1"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org"},"_hasShrinkwrap":false,"packageManager":"pnpm@10.6.1","devDependencies":{"shx":"^0.4.0","husky":"^9.1.7","eslint":"^9.28.0","vitest":"^2.1.9","@types/ws":"^8.18.1","typescript":"^5.8.3","@types/node":"^20.19.8","lint-staged":"^15.2.11","@types/lodash-es":"^4.17.12","@antfu/eslint-config":"^4.13.2","eslint-plugin-format":"^1.0.1"},"_npmOperationalInternal":{"tmp":"tmp/mcp-use_0.1.8_1752831650592_0.022243257046953513","host":"s3://npm-registry-packages-npm-production"}},"0.1.9":{"name":"@agentpaid/mcp-use","type":"module","version":"0.1.9","packageManager":"pnpm@10.6.1","description":"A utility library for integrating Model Context Protocol (MCP) with LangChain, Zod, and related tools. Provides helpers for schema conversion, event streaming, and SDK usage.","author":{"name":"Zane"},"license":"MIT","homepage":"https://github.com/mcp-use/mcp-use-ts#readme","repository":{"type":"git","url":"git+https://github.com/mcp-use/mcp-use-ts.git"},"bugs":{"url":"https://github.com/mcp-use/mcp-use-ts/issues"},"keywords":["MCP","Model Context Protocol","LangChain","Zod","schema","SDK","eventsource","AI","utility","typescript"],"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist-cjs/index.js"}},"main":"./dist-cjs/index.js","module":"./dist/index.js","types":"./dist/index.d.ts","engines":{"node":">=22.0.0"},"publishConfig":{"registry":"https://registry.npmjs.org","access":"public"},"scripts":{"build":"shx rm -rf dist && tsc","build:cjs":"shx rm -rf dist-cjs && tsc --project tsconfig.cjs.json && node scripts/create-cjs-package.cjs","build:all":"npm run build && npm run build:cjs","lint":"eslint","lint:fix":"eslint --fix","test":"vitest","test:run":"vitest run","test:simple":"vitest run tests/stream_events_simple.test.ts","test:integration":"vitest run tests/stream_events.test.ts","watch":"tsc --watch","start":"node dist/index.js","prepublishOnly":"npm run build:all","fmt":"eslint --fix","release":"npm version patch --tag-version-prefix=v && git push --follow-tags","release:minor":"npm version minor --tag-version-prefix=v && git push --follow-tags","release:major":"npm version major --tag-version-prefix=v && git push --follow-tags","prepare":"husky","example:airbnb":"npm run build && node dist/examples/airbnb_use.js","example:browser":"npm run build && node dist/examples/browser_use.js","example:chat":"npm run build && node dist/examples/chat_example.js","example:stream":"npm run build && node dist/examples/stream_example.js","example:stream_events":"npm run build && node dist/examples/stream_events_example.js","example:ai_sdk":"npm run build && node dist/examples/ai_sdk_example.js","example:filesystem":"npm run build && node dist/examples/filesystem_use.js","example:http":"npm run build && node dist/examples/http_example.js","example:everything":"npm run build && node dist/examples/mcp_everything.js","example:multi":"npm run build && node dist/examples/multi_server_example.js","example:sandbox":"npm run build && node dist/examples/sandbox_everything.js","example:oauth":"npm run build && node dist/examples/simple_oauth_example.js","example:blender":"npm run build && node dist/examples/blender_use.js","example:add_server":"npm run build && node dist/examples/add_server_tool.js"},"dependencies":{"@dmitryrechkin/json-schema-to-zod":"^1.0.1","@langchain/anthropic":"^0.3.14","@langchain/core":"0.3.58","@langchain/openai":"^0.5.15","@modelcontextprotocol/sdk":"1.12.1","@scarf/scarf":"^1.4.0","ai":"^4.3.19","dotenv":"^16.5.0","eventsource":"^3.0.6","fastembed":"^1.14.4","langchain":"^0.3.27","lodash":"^4.17.21","lodash-es":"^4.17.21","posthog-node":"^5.1.1","uuid":"^11.1.0","winston":"^3.17.0","ws":"^8.18.2","zod":"^3.25.48","zod-to-json-schema":"^3.24.5"},"devDependencies":{"@antfu/eslint-config":"^4.13.2","@types/lodash-es":"^4.17.12","@types/node":"^20.19.8","@types/ws":"^8.18.1","eslint":"^9.28.0","eslint-plugin-format":"^1.0.1","husky":"^9.1.7","lint-staged":"^15.2.11","shx":"^0.4.0","typescript":"^5.8.3","vitest":"^2.1.9"},"lint-staged":{"*.{js,ts}":["npm run lint"],"**/*.ts":["npm run build"]},"_id":"@agentpaid/mcp-use@0.1.9","gitHead":"b49d2855058985091cb90eca22b28e3ebdb3415c","_nodeVersion":"23.6.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-0ZuhgCQOvI3yUC2UpFvMIXmSYQpy4OMZwy0mz0s8CJ9iw4tPDWeqhmPNquF0Ww2bFxZL3k6kyZAnUCiG9eACjQ==","shasum":"720d766a0364fe6ccc4ea9ffb1d19b9e71e6dd24","tarball":"https://registry.npmjs.org/@agentpaid/mcp-use/-/mcp-use-0.1.9.tgz","fileCount":164,"unpackedSize":374450,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQC4EBY0aDGNKxD9HOWBu2DFHY9mcnE7ZTMPQmLPrzJx8gIhAIOLCsfc6diKMcNsH2CS3b918YkOuKqymxrdAG0YZQOL"}]},"_npmUser":{"name":"rdosanjh","email":"rdosanjh73@gmail.com"},"directories":{},"maintainers":[{"name":"rdosanjh","email":"rdosanjh73@gmail.com"},{"name":"georgi-paid","email":"georgi@paid.ai"},{"name":"zhalyn","email":"zhalyn@paid.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/mcp-use_0.1.9_1752831943367_0.11700386168915355"},"_hasShrinkwrap":false}},"time":{"created":"2025-07-18T09:36:58.773Z","modified":"2025-07-18T09:45:44.121Z","0.1.7":"2025-07-18T09:36:59.037Z","0.1.8":"2025-07-18T09:40:50.798Z","0.1.9":"2025-07-18T09:45:43.542Z"},"bugs":{"url":"https://github.com/mcp-use/mcp-use-ts/issues"},"author":{"name":"Zane"},"license":"MIT","homepage":"https://github.com/mcp-use/mcp-use-ts#readme","keywords":["MCP","Model Context Protocol","LangChain","Zod","schema","SDK","eventsource","AI","utility","typescript"],"repository":{"type":"git","url":"git+https://github.com/mcp-use/mcp-use-ts.git"},"description":"A utility library for integrating Model Context Protocol (MCP) with LangChain, Zod, and related tools. Provides helpers for schema conversion, event streaming, and SDK usage.","maintainers":[{"name":"rdosanjh","email":"rdosanjh73@gmail.com"},{"name":"georgi-paid","email":"georgi@paid.ai"},{"name":"zhalyn","email":"zhalyn@paid.ai"}],"readme":"<div align=\"center\" style=\"margin: 0 auto; max-width: 80%;\">\n  <picture>\n    <source media=\"(prefers-color-scheme: dark)\" srcset=\"./static/logo_white.svg\">\n    <source media=\"(prefers-color-scheme: light)\" srcset=\"./static/logo_black.svg\">\n    <img alt=\"mcp use logo\" src=\"./static/logo_white.svg\" width=\"80%\" style=\"margin: 20px auto;\">\n  </picture>\n</div>\n\n<h1 align=\"center\">Unified MCP Client Library</h1>\n\n<p align=\"center\">\n    <a href=\"https://www.npmjs.com/package/mcp-use\" alt=\"NPM Downloads\">\n        <img src=\"https://img.shields.io/npm/dw/mcp-use.svg\"/></a>\n    <a href=\"https://www.npmjs.com/package/mcp-use\" alt=\"NPM Version\">\n        <img src=\"https://img.shields.io/npm/v/mcp-use.svg\"/></a>\n    <a href=\"https://docs.mcp-use.io\" alt=\"Documentation\">\n        <img src=\"https://img.shields.io/badge/docs-mcp--use.io-blue\" /></a>\n    <a href=\"https://mcp-use.io\" alt=\"Website\">\n        <img src=\"https://img.shields.io/badge/website-mcp--use.io-blue\" /></a>\n    <a href=\"https://github.com/mcp-use/mcp-use-ts/blob/main/LICENSE\" alt=\"License\">\n        <img src=\"https://img.shields.io/github/license/mcp-use/mcp-use-ts\" /></a>\n    <a href=\"https://eslint.org\" alt=\"Code style: ESLint\">\n        <img src=\"https://img.shields.io/badge/code%20style-eslint-4B32C3.svg\" /></a>\n    <a href=\"https://github.com/mcp-use/mcp-use-ts/stargazers\" alt=\"GitHub stars\">\n        <img src=\"https://img.shields.io/github/stars/mcp-use/mcp-use-ts?style=social\" /></a>\n    <a href=\"https://discord.gg/XkNkSkMz3V\" alt=\"Discord\">\n        <img src=\"https://dcbadge.limes.pink/api/server/XkNkSkMz3V?style=flat\" /></a>\n</p>\n\n🌐 **MCP Client** is the open-source way to connect **any LLM to any MCP server** in TypeScript/Node.js, letting you build custom agents with tool access without closed-source dependencies.\n\n💡 Let developers easily connect any LLM via LangChain.js to tools like web browsing, file operations, 3D modeling, and more.\n\n---\n\n## ✨ Key Features\n\n| Feature                         | Description                                                                |\n| ------------------------------- | -------------------------------------------------------------------------- |\n| 🔄 **Ease of use**              | Create an MCP-capable agent in just a few lines of TypeScript.             |\n| 🤖 **LLM Flexibility**          | Works with any LangChain.js-supported LLM that supports tool calling.      |\n| 🌐 **HTTP Support**             | Direct SSE/HTTP connection to MCP servers.                                 |\n| ⚙️ **Dynamic Server Selection** | Agents select the right MCP server from a pool on the fly.                 |\n| 🧩 **Multi-Server Support**     | Use multiple MCP servers in one agent.                                     |\n| 🛡️ **Tool Restrictions**        | Restrict unsafe tools like filesystem or network.                          |\n| 🔧 **Custom Agents**            | Build your own agents with LangChain.js adapter or implement new adapters. |\n\n---\n\n## 🚀 Quick Start\n\n### Requirements\n\n- Node.js 22.0.0 or higher\n- npm, yarn, or pnpm (examples use pnpm)\n\n### Installation\n\n```bash\n# Install from npm\nnpm install mcp-use\n# LangChain.js and your LLM provider (e.g., OpenAI)\nnpm install langchain @langchain/openai dotenv\n```\n\nCreate a `.env`:\n\n```ini\nOPENAI_API_KEY=your_api_key\n```\n\n### Basic Usage\n\n```ts\nimport { ChatOpenAI } from '@langchain/openai'\nimport { MCPAgent, MCPClient } from 'mcp-use'\nimport 'dotenv/config'\n\nasync function main() {\n  // 1. Configure MCP servers\n  const config = {\n    mcpServers: {\n      playwright: { command: 'npx', args: ['@playwright/mcp@latest'] }\n    }\n  }\n  const client = MCPClient.fromDict(config)\n\n  // 2. Create LLM\n  const llm = new ChatOpenAI({ modelName: 'gpt-4o' })\n\n  // 3. Instantiate agent\n  const agent = new MCPAgent({ llm, client, maxSteps: 20 })\n\n  // 4. Run query\n  const result = await agent.run('Find the best restaurant in Tokyo using Google Search')\n  console.log('Result:', result)\n}\n\nmain().catch(console.error)\n```\n\n---\n\n## 🔧 API Methods\n\n### MCPAgent Methods\n\nThe `MCPAgent` class provides several methods for executing queries with different output formats:\n\n#### `run(query: string, maxSteps?: number): Promise<string>`\n\nExecutes a query and returns the final result as a string.\n\n```ts\nconst result = await agent.run('What tools are available?')\nconsole.log(result)\n```\n\n#### `stream(query: string, maxSteps?: number): AsyncGenerator<AgentStep, string, void>`\n\nYields intermediate steps during execution, providing visibility into the agent's reasoning process.\n\n```ts\nconst stream = agent.stream('Search for restaurants in Tokyo')\nfor await (const step of stream) {\n  console.log(`Tool: ${step.action.tool}, Input: ${step.action.toolInput}`)\n  console.log(`Result: ${step.observation}`)\n}\n```\n\n#### `streamEvents(query: string, maxSteps?: number): AsyncGenerator<StreamEvent, void, void>`\n\nYields fine-grained LangChain StreamEvent objects, enabling token-by-token streaming and detailed event tracking.\n\n```ts\nconst eventStream = agent.streamEvents('What is the weather today?')\nfor await (const event of eventStream) {\n  // Handle different event types\n  switch (event.event) {\n    case 'on_chat_model_stream':\n      // Token-by-token streaming from the LLM\n      if (event.data?.chunk?.content) {\n        process.stdout.write(event.data.chunk.content)\n      }\n      break\n    case 'on_tool_start':\n      console.log(`\\nTool started: ${event.name}`)\n      break\n    case 'on_tool_end':\n      console.log(`Tool completed: ${event.name}`)\n      break\n  }\n}\n```\n\n### Key Differences\n\n- **`run()`**: Best for simple queries where you only need the final result\n- **`stream()`**: Best for debugging and understanding the agent's tool usage\n- **`streamEvents()`**: Best for real-time UI updates with token-level streaming\n\n## 🔄 AI SDK Integration\n\nThe library provides built-in utilities for integrating with [Vercel AI SDK](https://sdk.vercel.ai/), making it easy to build streaming UIs with React hooks like `useCompletion` and `useChat`.\n\n### Installation\n\n```bash\nnpm install ai @langchain/anthropic\n```\n\n### Basic Usage\n\n```ts\nimport { ChatAnthropic } from '@langchain/anthropic'\nimport { LangChainAdapter } from 'ai'\nimport { createReadableStreamFromGenerator, MCPAgent, MCPClient, streamEventsToAISDK } from 'mcp-use'\n\nasync function createApiHandler() {\n  const config = {\n    mcpServers: {\n      everything: { command: 'npx', args: ['-y', '@modelcontextprotocol/server-everything'] }\n    }\n  }\n\n  const client = new MCPClient(config)\n  const llm = new ChatAnthropic({ model: 'claude-sonnet-4-20250514' })\n  const agent = new MCPAgent({ llm, client, maxSteps: 5 })\n\n  return async (request: { prompt: string }) => {\n    const streamEvents = agent.streamEvents(request.prompt)\n    const aiSDKStream = streamEventsToAISDK(streamEvents)\n    const readableStream = createReadableStreamFromGenerator(aiSDKStream)\n\n    return LangChainAdapter.toDataStreamResponse(readableStream)\n  }\n}\n```\n\n### Enhanced Usage with Tool Visibility\n\n```ts\nimport { streamEventsToAISDKWithTools } from 'mcp-use'\n\nasync function createEnhancedApiHandler() {\n  const config = {\n    mcpServers: {\n      everything: { command: 'npx', args: ['-y', '@modelcontextprotocol/server-everything'] }\n    }\n  }\n\n  const client = new MCPClient(config)\n  const llm = new ChatAnthropic({ model: 'claude-sonnet-4-20250514' })\n  const agent = new MCPAgent({ llm, client, maxSteps: 8 })\n\n  return async (request: { prompt: string }) => {\n    const streamEvents = agent.streamEvents(request.prompt)\n    // Enhanced stream includes tool usage notifications\n    const enhancedStream = streamEventsToAISDKWithTools(streamEvents)\n    const readableStream = createReadableStreamFromGenerator(enhancedStream)\n\n    return LangChainAdapter.toDataStreamResponse(readableStream)\n  }\n}\n```\n\n### Next.js API Route Example\n\n```ts\n// pages/api/chat.ts or app/api/chat/route.ts\nimport { ChatAnthropic } from '@langchain/anthropic'\nimport { LangChainAdapter } from 'ai'\nimport { createReadableStreamFromGenerator, MCPAgent, MCPClient, streamEventsToAISDK } from 'mcp-use'\n\nexport async function POST(req: Request) {\n  const { prompt } = await req.json()\n\n  const config = {\n    mcpServers: {\n      everything: { command: 'npx', args: ['-y', '@modelcontextprotocol/server-everything'] }\n    }\n  }\n\n  const client = new MCPClient(config)\n  const llm = new ChatAnthropic({ model: 'claude-sonnet-4-20250514' })\n  const agent = new MCPAgent({ llm, client, maxSteps: 10 })\n\n  try {\n    const streamEvents = agent.streamEvents(prompt)\n    const aiSDKStream = streamEventsToAISDK(streamEvents)\n    const readableStream = createReadableStreamFromGenerator(aiSDKStream)\n\n    return LangChainAdapter.toDataStreamResponse(readableStream)\n  }\n  finally {\n    await client.closeAllSessions()\n  }\n}\n```\n\n### Frontend Integration\n\n```tsx\n// components/Chat.tsx\nimport { useCompletion } from 'ai/react'\n\nexport function Chat() {\n  const { completion, input, handleInputChange, handleSubmit } = useCompletion({\n    api: '/api/chat',\n  })\n\n  return (\n    <div>\n      <div>{completion}</div>\n      <form onSubmit={handleSubmit}>\n        <input\n          value={input}\n          onChange={handleInputChange}\n          placeholder=\"Ask me anything...\"\n        />\n      </form>\n    </div>\n  )\n}\n```\n\n### Available AI SDK Utilities\n\n- **`streamEventsToAISDK()`**: Converts streamEvents to basic text stream\n- **`streamEventsToAISDKWithTools()`**: Enhanced stream with tool usage notifications\n- **`createReadableStreamFromGenerator()`**: Converts async generator to ReadableStream\n\n---\n\n## 📂 Configuration File\n\nYou can store servers in a JSON file:\n\n```json\n{\n  \"mcpServers\": {\n    \"playwright\": {\n      \"command\": \"npx\",\n      \"args\": [\"@playwright/mcp@latest\"]\n    }\n  }\n}\n```\n\nLoad it:\n\n```ts\nimport { MCPClient } from 'mcp-use'\n\nconst client = MCPClient.fromConfigFile('./mcp-config.json')\n```\n\n---\n\n## 📚 Examples\n\nWe provide a comprehensive set of examples demonstrating various use cases. All examples are located in the `examples/` directory with a dedicated README.\n\n### Running Examples\n\n```bash\n# Install dependencies\nnpm install\n\n# Run any example\nnpm run example:airbnb      # Search accommodations with Airbnb\nnpm run example:browser     # Browser automation with Playwright\nnpm run example:chat        # Interactive chat with memory\nnpm run example:stream      # Demonstrate streaming methods (stream & streamEvents)\nnpm run example:stream_events # Comprehensive streamEvents() examples\nnpm run example:ai_sdk      # AI SDK integration with streaming\nnpm run example:filesystem  # File system operations\nnpm run example:http        # HTTP server connection\nnpm run example:everything  # Test MCP functionalities\nnpm run example:multi       # Multiple servers in one session\n```\n\n### Example Highlights\n\n- **Browser Automation**: Control browsers to navigate websites and extract information\n- **File Operations**: Read, write, and manipulate files through MCP\n- **Multi-Server**: Combine multiple MCP servers (Airbnb + Browser) in a single task\n- **Sandboxed Execution**: Run MCP servers in isolated E2B containers\n- **OAuth Flows**: Authenticate with services like Linear using OAuth2\n- **Streaming Methods**: Demonstrate both step-by-step and token-level streaming\n- **AI SDK Integration**: Build streaming UIs with Vercel AI SDK and React hooks\n\nSee the [examples README](./examples/README.md) for detailed documentation and prerequisites.\n\n---\n\n## 🔄 Multi-Server Example\n\n```ts\nconst config = {\n  mcpServers: {\n    airbnb: { command: 'npx', args: ['@openbnb/mcp-server-airbnb'] },\n    playwright: { command: 'npx', args: ['@playwright/mcp@latest'] }\n  }\n}\nconst client = MCPClient.fromDict(config)\nconst agent = new MCPAgent({ llm, client, useServerManager: true })\nawait agent.run('Search Airbnb in Barcelona, then Google restaurants nearby')\n```\n\n---\n\n## 🔒 Tool Access Control\n\n```ts\nconst agent = new MCPAgent({\n  llm,\n  client,\n  disallowedTools: ['file_system', 'network']\n})\n```\n\n## 👥 Contributors\n\n<table>\n<tr>\n    <td align=\"center\" style=\"word-wrap: break-word; width: 150.0; height: 150.0\">\n        <a href=https://github.com/pietrozullo>\n            <img src=https://avatars.githubusercontent.com/u/62951181?v=4 width=\"100;\"  style=\"border-radius:50%;align-items:center;justify-content:center;overflow:hidden;padding-top:10px\" alt=Pietro Zullo/>\n            <br />\n            <sub style=\"font-size:14px\"><b>Pietro Zullo</b></sub>\n        </a>\n    </td>\n    <td align=\"center\" style=\"word-wrap: break-word; width: 150.0; height: 150.0\">\n        <a href=https://github.com/zandko>\n            <img src=https://avatars.githubusercontent.com/u/37948383?v=4 width=\"100;\"  style=\"border-radius:50%;align-items:center;justify-content:center;overflow:hidden;padding-top:10px\" alt=Zane/>\n            <br />\n            <sub style=\"font-size:14px\"><b>Zane</b></sub>\n        </a>\n    </td>\n    <td align=\"center\" style=\"word-wrap: break-word; width: 150.0; height: 150.0\">\n        <a href=https://github.com/Pederzh>\n            <img src=https://avatars.githubusercontent.com/u/11487621?v=4 width=\"100;\"  style=\"border-radius:50%;align-items:center;justify-content:center;overflow:hidden;padding-top:10px\" alt=Luigi Pederzani/>\n            <br />\n            <sub style=\"font-size:14px\"><b>Luigi Pederzani</b></sub>\n        </a>\n    </td>\n</tr>\n</table>\n\n<!-- Contributors section will be automatically generated here -->\n\n## 📜 License\n\nMIT © [Zane](https://github.com/zandko)\n","readmeFilename":"README.md"}