{"_id":"@ag-ui/mcp-middleware","_rev":"2-d753e0f326fee6080053a0e28d6cb37c","name":"@ag-ui/mcp-middleware","dist-tags":{"latest":"0.0.2"},"versions":{"0.0.1":{"name":"@ag-ui/mcp-middleware","version":"0.0.1","author":{"name":"Markus Ecker","email":"markus.ecker@gmail.com"},"_id":"@ag-ui/mcp-middleware@0.0.1","maintainers":[{"name":"_mme","email":"markus.ecker@gmail.com"},{"name":"copilotkit","email":"devops@copilotkit.ai"}],"dist":{"shasum":"7d5615b653968e3c72a19431e980914f0bb67e3d","tarball":"https://registry.npmjs.org/@ag-ui/mcp-middleware/-/mcp-middleware-0.0.1.tgz","fileCount":11,"integrity":"sha512-TayUu7kB+jXUTPRUJesNvJYrP+0weTL9F2VJJ8QQ4sWxY/Ihjo+GgFYgJZYNcLwbo1DKgmVJtdm2XUouPCbxeg==","signatures":[{"sig":"MEQCIDLLtzXbfKo+xqjrsl79UYhApLPWCH8bc+ClU5845A2hAiAIf16K4q3dO4uvpzvZMBiY7vyjTmY33OwBoFLDfuaBLw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":78285},"main":"./dist/index.js","_from":"file:ag-ui-mcp-middleware-0.0.1.tgz","types":"./dist/index.d.ts","module":"./dist/index.mjs","exports":{".":{"import":"./dist/index.mjs","require":"./dist/index.js"},"./package.json":"./package.json"},"scripts":{"dev":"tsdown --watch","test":"vitest run","build":"tsdown","clean":"git clean -fdX --exclude=\"!.env\"","typecheck":"tsc --noEmit","test:watch":"vitest","link:global":"pnpm link --global","test:exports":"publint --strict && attw --pack","test:coverage":"vitest run --coverage","unlink:global":"pnpm unlink --global"},"_npmUser":{"name":"_mme","email":"markus.ecker@gmail.com"},"_resolved":"/Users/mme/Projects/AG-UI/main/middlewares/mcp-middleware/ag-ui-mcp-middleware-0.0.1.tgz","_integrity":"sha512-TayUu7kB+jXUTPRUJesNvJYrP+0weTL9F2VJJ8QQ4sWxY/Ihjo+GgFYgJZYNcLwbo1DKgmVJtdm2XUouPCbxeg==","_npmVersion":"11.11.0","description":"AG-UI middleware that connects an agent run to one or more [MCP](https://modelcontextprotocol.io) servers. It lists each server's tools, injects them into the run, executes the resulting tool calls server-side, and loops the agent until no MCP tool calls ","directories":{},"sideEffects":false,"_nodeVersion":"24.14.1","dependencies":{"@ag-ui/client":"0.0.54","@modelcontextprotocol/sdk":"^1.0.0"},"_hasShrinkwrap":false,"devDependencies":{"tsdown":"^0.20.1","vitest":"^4.0.18","publint":"^0.3.12","typescript":"^5.3.3","@types/node":"^20.11.19","@arethetypeswrong/cli":"^0.17.4","@vitest/coverage-istanbul":"^4.0.18"},"peerDependencies":{"rxjs":"7.8.1"},"_npmOperationalInternal":{"tmp":"tmp/mcp-middleware_0.0.1_1780312662216_0.7020496916133583","host":"s3://npm-registry-packages-npm-production"}},"0.0.2":{"_id":"@ag-ui/mcp-middleware@0.0.2","bugs":{"url":"https://github.com/ag-ui-protocol/ag-ui/issues"},"dist":{"shasum":"a87e0f362c3589c367750fd14bffb9d55f35848e","tarball":"https://registry.npmjs.org/@ag-ui/mcp-middleware/-/mcp-middleware-0.0.2.tgz","fileCount":11,"integrity":"sha512-+CwY9SUjXTvk1h77/nqpXEPj79i/Gt0G7ZEcZLlYsJHJkYYC8IG9yN/tiR++HS1Qb1R46btomrgoBfpBvpGwDw==","signatures":[{"sig":"MEYCIQCkppGIYghkSrV1d6JPtZ364mNPS/8FCx0Qe8yz5bVspgIhAL5xFT8IuWXq6J2ZCUei+MrypSsOKl8358wRoHdNGDmu","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIAmINDy7TxoW3htIbR9q4ZJBKBtgscbJPDGLbT3AhZKNAiEAtouCvmPQXX6Gq/sA85CtBbfWZcIkmFm4EWMzBbnj500="}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@ag-ui%2fmcp-middleware@0.0.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":80879},"main":"./dist/index.js","name":"@ag-ui/mcp-middleware","_from":"file:ag-ui-mcp-middleware-0.0.2.tgz","types":"./dist/index.d.ts","author":{"name":"Markus Ecker","email":"markus.ecker@gmail.com"},"module":"./dist/index.mjs","exports":{".":{"import":"./dist/index.mjs","require":"./dist/index.js"},"./package.json":"./package.json"},"license":"MIT","scripts":{"dev":"tsdown --watch","test":"vitest run","build":"tsdown","clean":"git clean -fdX --exclude=\"!.env\"","typecheck":"tsc --noEmit","test:watch":"vitest","link:global":"pnpm link --global","test:exports":"publint --strict && attw --pack","test:coverage":"vitest run --coverage","unlink:global":"pnpm unlink --global"},"version":"0.0.2","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:ad8fa307-e045-4b67-97d9-836cb7f3e942"}},"homepage":"https://github.com/ag-ui-protocol/ag-ui#readme","_resolved":"/home/runner/work/ag-ui/ag-ui/middlewares/mcp-middleware/ag-ui-mcp-middleware-0.0.2.tgz","_integrity":"sha512-+CwY9SUjXTvk1h77/nqpXEPj79i/Gt0G7ZEcZLlYsJHJkYYC8IG9yN/tiR++HS1Qb1R46btomrgoBfpBvpGwDw==","repository":{"url":"git+https://github.com/ag-ui-protocol/ag-ui.git","type":"git"},"_npmVersion":"11.15.0","description":"AG-UI middleware that connects an agent run to one or more [MCP](https://modelcontextprotocol.io) servers. It lists each server's tools, injects them into the run, executes the resulting tool calls server-side, and loops the agent until no MCP tool calls ","directories":{},"maintainers":[{"name":"_mme","email":"markus.ecker@gmail.com"},{"name":"copilotkit","email":"devops@copilotkit.ai"}],"sideEffects":false,"_nodeVersion":"22.23.2","dependencies":{"@modelcontextprotocol/sdk":"^1.0.0"},"_hasShrinkwrap":false,"devDependencies":{"tsdown":"^0.20.1","vitest":"^4.0.18","publint":"^0.3.12","typescript":"^5.3.3","@types/node":"^20.11.19","@ag-ui/client":"0.0.59","@arethetypeswrong/cli":"^0.17.4","@vitest/coverage-istanbul":"^4.0.18"},"peerDependencies":{"rxjs":"7.8.1","@ag-ui/client":">=0.0.40"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/mcp-middleware_0.0.2_1789156979926_0.46785431137937117"}}},"time":{"created":"2026-06-01T11:17:42.034Z","modified":"2026-09-11T20:03:00.370Z","0.0.1":"2026-06-01T11:17:42.352Z","0.0.2":"2026-09-11T20:03:00.017Z"},"author":{"name":"Markus Ecker","email":"markus.ecker@gmail.com"},"description":"AG-UI middleware that connects an agent run to one or more [MCP](https://modelcontextprotocol.io) servers. It lists each server's tools, injects them into the run, executes the resulting tool calls server-side, and loops the agent until no MCP tool calls ","maintainers":[{"name":"_mme","email":"markus.ecker@gmail.com"},{"name":"copilotkit","email":"devops@copilotkit.ai"}],"readme":"# MCP Middleware\n\nAG-UI middleware that connects an agent run to one or more [MCP](https://modelcontextprotocol.io)\nservers. It lists each server's tools, injects them into the run, executes the\nresulting tool calls server-side, and loops the agent until no MCP tool calls\nremain — all presented to the consumer as a single, continuous run.\n\n## Usage\n\n```ts\nimport { MCPMiddleware } from \"@ag-ui/mcp-middleware\";\n\nagent.use(\n  new MCPMiddleware([\n    {\n      type: \"http\",\n      url: \"https://example.com/mcp\",\n      serverId: \"example\",\n      headers: { Authorization: \"Bearer <token>\" },\n    },\n  ]),\n);\n```\n\n## Behavior\n\n- **Tool injection.** Every tool reported by a server is exposed to the agent\n  namespaced as `mcp__{serverId}__{tool}` (sanitized to `[a-zA-Z0-9_-]`,\n  truncated to 64 characters, and de-duplicated with a `_N` suffix on\n  collision). `serverId` defaults to `server{index}` when omitted. Listing\n  happens once per middleware instance and is cached.\n- **Execution loop.** When a finished run leaves MCP tool calls open, the\n  middleware executes them (in parallel), emits a `TOOL_CALL_RESULT` for each,\n  and — if nothing else is open — starts another run with the results appended.\n  If non-MCP tool calls remain open (e.g. frontend tools), it stops and hands\n  off to the frontend. Tool calls that don't target an injected MCP tool are\n  never touched.\n- **Single-run presentation.** The whole multi-iteration loop looks like one\n  run to the consumer: the first `RUN_STARTED` is forwarded, continuation\n  `RUN_STARTED` events are suppressed, and a single terminal `RUN_FINISHED` is\n  flushed only when the loop stops.\n- **Runaway guard.** `maxIterations` (default `32`) caps the number of\n  tool-execution rounds. Values are clamped to a positive integer.\n\n## Configuration\n\n```ts\ninterface MCPClientConfig {\n  type: \"http\" | \"sse\";\n  url: string;\n  serverId?: string;\n  headers?: Record<string, string>;\n}\n\ninterface MCPMiddlewareOptions {\n  maxIterations?: number; // default 32\n}\n```\n\nPer-request auth is supported by constructing the middleware per request with\n`headers` set — they're stamped on outbound MCP requests via the transport's\n`requestInit`.\n\n> **SSE caveat:** for the `sse` transport, `headers` only apply to the POST\n> channel; the SSE event stream uses `eventSourceInit`. Prefer the `http`\n> (streamable) transport when headers must cover all traffic.\n","readmeFilename":"README.md","homepage":"https://github.com/ag-ui-protocol/ag-ui#readme","repository":{"url":"git+https://github.com/ag-ui-protocol/ag-ui.git","type":"git"},"bugs":{"url":"https://github.com/ag-ui-protocol/ag-ui/issues"},"license":"MIT"}