@alvin0/ai-agent-sdk-mcp-node 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +39 -0
- package/dist/index.d.mts +13 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +48 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +76 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 alvin0 (chaulamdinhai) <chaulamdinhai@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# @alvin0/ai-agent-sdk-mcp-node
|
|
2
|
+
|
|
3
|
+
Runtime: **Node 22.12+**.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
pnpm add @alvin0/ai-agent-sdk-core @alvin0/ai-agent-sdk-mcp @alvin0/ai-agent-sdk-mcp-node
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Node-only MCP stdio client transport. Universal remote HTTP clients remain in
|
|
10
|
+
`@alvin0/ai-agent-sdk-mcp`; server hosting is selected separately through
|
|
11
|
+
`@alvin0/ai-agent-sdk-mcp-server` or `@alvin0/ai-agent-sdk-mcp-node-server`.
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { createAgentRuntime } from '@alvin0/ai-agent-sdk-core'
|
|
15
|
+
import { connectMcpStdio } from '@alvin0/ai-agent-sdk-mcp-node'
|
|
16
|
+
|
|
17
|
+
const runtime = await createAgentRuntime({ providers: [modelProvider] })
|
|
18
|
+
let connection: Awaited<ReturnType<typeof connectMcpStdio>> | undefined
|
|
19
|
+
try {
|
|
20
|
+
connection = await connectMcpStdio({
|
|
21
|
+
serverName: 'local-tools',
|
|
22
|
+
command: process.execPath,
|
|
23
|
+
args: ['path/to/server.js'],
|
|
24
|
+
logger: runtime.logger({ fields: { integration: 'mcp-stdio' } }),
|
|
25
|
+
})
|
|
26
|
+
const agent = runtime.agent({ model, toolSources: [connection] })
|
|
27
|
+
await agent.generate('Use the local tools when needed.')
|
|
28
|
+
} finally {
|
|
29
|
+
try {
|
|
30
|
+
await runtime.close()
|
|
31
|
+
} finally {
|
|
32
|
+
await connection?.closeWithReport()
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Composition: `runtime-agent.toolSources`. Lifecycle: `connected-caller-owned`;
|
|
38
|
+
create the runtime first, pass `runtime.logger(...)`, close the runtime before
|
|
39
|
+
the borrowed connection, and inspect `closeWithReport()`.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { StdioServerParameters } from "@modelcontextprotocol/client/stdio";
|
|
2
|
+
import { McpClientConnection, McpClientLifecycleOptions, McpCloseReport, McpConnectionError } from "@alvin0/ai-agent-sdk-mcp/client";
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
/** Stdio-specialized alias retained so normal Node recipes name their transport. */
|
|
5
|
+
interface McpStdioConnection extends McpClientConnection {}
|
|
6
|
+
interface McpStdioClientOptions extends McpClientLifecycleOptions, StdioServerParameters {}
|
|
7
|
+
/** Construct a supervised stdio client without spawning the child yet. */
|
|
8
|
+
declare function createMcpStdioClient(options: McpStdioClientOptions): McpStdioConnection;
|
|
9
|
+
/** Spawn, negotiate, discover tools, and return a ready stdio client. */
|
|
10
|
+
declare function connectMcpStdio(options: McpStdioClientOptions): Promise<McpStdioConnection>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { type McpCloseReport, McpConnectionError, McpStdioClientOptions, McpStdioConnection, connectMcpStdio, createMcpStdioClient };
|
|
13
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;UAaiB,2BAA2B;UAE3B,8BAA8B,2BAA2B;;iBAG1D,qBAAqB,SAAS,wBAAwB;;iBAiBhD,gBAAgB,SAAS,wBAAwB,QAAQ"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
|
2
|
+
import { McpClientConnection, McpConnectionError, McpConnectionError as McpConnectionError$1 } from "@alvin0/ai-agent-sdk-mcp/client";
|
|
3
|
+
|
|
4
|
+
//#region src/index.ts
|
|
5
|
+
/** Node-only MCP stdio client transport. */
|
|
6
|
+
/** Construct a supervised stdio client without spawning the child yet. */
|
|
7
|
+
function createMcpStdioClient(options) {
|
|
8
|
+
const { command, args, env, stderr, cwd, maxBufferSize, ...lifecycle } = options;
|
|
9
|
+
if (command.trim().length === 0) throw new TypeError("MCP stdio command must not be empty");
|
|
10
|
+
return new McpClientConnection(lifecycle, () => new StdioClientTransport({
|
|
11
|
+
command,
|
|
12
|
+
...args === void 0 ? {} : { args: [...args] },
|
|
13
|
+
...env === void 0 ? {} : { env: { ...env } },
|
|
14
|
+
...stderr === void 0 ? {} : { stderr },
|
|
15
|
+
...cwd === void 0 ? {} : { cwd },
|
|
16
|
+
...maxBufferSize === void 0 ? {} : { maxBufferSize }
|
|
17
|
+
}), { integrationFamily: "mcp-stdio-client" });
|
|
18
|
+
}
|
|
19
|
+
/** Spawn, negotiate, discover tools, and return a ready stdio client. */
|
|
20
|
+
async function connectMcpStdio(options) {
|
|
21
|
+
const connection = createMcpStdioClient(options);
|
|
22
|
+
try {
|
|
23
|
+
await connection.connect();
|
|
24
|
+
return connection;
|
|
25
|
+
} catch (error) {
|
|
26
|
+
const cleanup = await connection.closeWithReport();
|
|
27
|
+
throw new McpConnectionError$1(connection.state.status === "connecting" ? "handshake" : "unknown", {
|
|
28
|
+
code: "MCP_CONNECT_FAILED",
|
|
29
|
+
stage: "stdio-connect",
|
|
30
|
+
message: "MCP stdio connection startup failed",
|
|
31
|
+
usageCoverage: {
|
|
32
|
+
logicalCalls: 0,
|
|
33
|
+
attempts: 0,
|
|
34
|
+
complete: 0,
|
|
35
|
+
partial: 0,
|
|
36
|
+
estimated: 0,
|
|
37
|
+
missing: 0,
|
|
38
|
+
notApplicable: 0,
|
|
39
|
+
possiblyBilledAttemptsWithoutUsage: 0
|
|
40
|
+
},
|
|
41
|
+
possiblyBilledAttemptsWithoutUsage: 0
|
|
42
|
+
}, cleanup, error);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
export { McpConnectionError, connectMcpStdio, createMcpStdioClient };
|
|
48
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["McpConnectionError"],"sources":["../src/index.ts"],"sourcesContent":["/** Node-only MCP stdio client transport. */\n\nimport { StdioClientTransport, type StdioServerParameters } from '@modelcontextprotocol/client/stdio'\nimport {\n McpConnectionError,\n McpClientConnection,\n type McpClientLifecycleOptions,\n} from '@alvin0/ai-agent-sdk-mcp/client'\n\nexport { McpConnectionError } from '@alvin0/ai-agent-sdk-mcp/client'\nexport type { McpCloseReport } from '@alvin0/ai-agent-sdk-mcp/client'\n\n/** Stdio-specialized alias retained so normal Node recipes name their transport. */\nexport interface McpStdioConnection extends McpClientConnection {}\n\nexport interface McpStdioClientOptions extends McpClientLifecycleOptions, StdioServerParameters {}\n\n/** Construct a supervised stdio client without spawning the child yet. */\nexport function createMcpStdioClient(options: McpStdioClientOptions): McpStdioConnection {\n const {\n command, args, env, stderr, cwd, maxBufferSize,\n ...lifecycle\n } = options\n if (command.trim().length === 0) throw new TypeError('MCP stdio command must not be empty')\n return new McpClientConnection(lifecycle, () => new StdioClientTransport({\n command,\n ...(args === undefined ? {} : { args: [...args] }),\n ...(env === undefined ? {} : { env: { ...env } }),\n ...(stderr === undefined ? {} : { stderr }),\n ...(cwd === undefined ? {} : { cwd }),\n ...(maxBufferSize === undefined ? {} : { maxBufferSize }),\n }), { integrationFamily: 'mcp-stdio-client' })\n}\n\n/** Spawn, negotiate, discover tools, and return a ready stdio client. */\nexport async function connectMcpStdio(options: McpStdioClientOptions): Promise<McpStdioConnection> {\n const connection = createMcpStdioClient(options)\n try {\n await connection.connect()\n return connection\n } catch (error: unknown) {\n const cleanup = await connection.closeWithReport()\n throw new McpConnectionError(\n connection.state.status === 'connecting' ? 'handshake' : 'unknown',\n {\n code: 'MCP_CONNECT_FAILED', stage: 'stdio-connect', message: 'MCP stdio connection startup failed',\n usageCoverage: { logicalCalls: 0, attempts: 0, complete: 0, partial: 0, estimated: 0,\n missing: 0, notApplicable: 0, possiblyBilledAttemptsWithoutUsage: 0 },\n possiblyBilledAttemptsWithoutUsage: 0,\n },\n cleanup,\n error,\n )\n }\n}\n"],"mappings":";;;;;;AAkBA,SAAgB,qBAAqB,SAAoD;CACvF,MAAM,EACJ,SAAS,MAAM,KAAK,QAAQ,KAAK,eACjC,GAAG,cACD;CACJ,IAAI,QAAQ,KAAK,CAAC,CAAC,WAAW,GAAG,MAAM,IAAI,UAAU,qCAAqC;CAC1F,OAAO,IAAI,oBAAoB,iBAAiB,IAAI,qBAAqB;EACvE;EACA,GAAI,SAAS,SAAY,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,IAAI,EAAE;EAChD,GAAI,QAAQ,SAAY,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE;EAC/C,GAAI,WAAW,SAAY,CAAC,IAAI,EAAE,OAAO;EACzC,GAAI,QAAQ,SAAY,CAAC,IAAI,EAAE,IAAI;EACnC,GAAI,kBAAkB,SAAY,CAAC,IAAI,EAAE,cAAc;CACzD,CAAC,GAAG,EAAE,mBAAmB,mBAAmB,CAAC;AAC/C;;AAGA,eAAsB,gBAAgB,SAA6D;CACjG,MAAM,aAAa,qBAAqB,OAAO;CAC/C,IAAI;EACF,MAAM,WAAW,QAAQ;EACzB,OAAO;CACT,SAAS,OAAgB;EACvB,MAAM,UAAU,MAAM,WAAW,gBAAgB;EACjD,MAAM,IAAIA,qBACR,WAAW,MAAM,WAAW,eAAe,cAAc,WACzD;GACE,MAAM;GAAsB,OAAO;GAAiB,SAAS;GAC7D,eAAe;IAAE,cAAc;IAAG,UAAU;IAAG,UAAU;IAAG,SAAS;IAAG,WAAW;IACjF,SAAS;IAAG,eAAe;IAAG,oCAAoC;GAAE;GACtE,oCAAoC;EACtC,GACA,SACA,KACF;CACF;AACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@alvin0/ai-agent-sdk-mcp-node",
|
|
3
|
+
"author": {
|
|
4
|
+
"name": "alvin0 - chaulamdinhai",
|
|
5
|
+
"email": "chaulamdinhai@gmail.com"
|
|
6
|
+
},
|
|
7
|
+
"version": "0.1.0",
|
|
8
|
+
"description": "Node stdio MCP client transport for ai-agent-sdk",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/alvin0/ai-agent-sdk.git",
|
|
13
|
+
"directory": "packages/mcp-node"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/alvin0/ai-agent-sdk/tree/main/packages/mcp-node#readme",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/alvin0/ai-agent-sdk/issues"
|
|
18
|
+
},
|
|
19
|
+
"type": "module",
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE"
|
|
25
|
+
],
|
|
26
|
+
"main": "./dist/index.mjs",
|
|
27
|
+
"types": "./dist/index.d.mts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.mts",
|
|
31
|
+
"import": "./dist/index.mjs",
|
|
32
|
+
"default": "./dist/index.mjs"
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public",
|
|
38
|
+
"provenance": true
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@alvin0/ai-agent-sdk-mcp": "^0.1.0",
|
|
42
|
+
"@modelcontextprotocol/client": "2.0.0"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"@alvin0/ai-agent-sdk-core": "^0.1.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@alvin0/ai-agent-sdk-core": "^0.1.0",
|
|
49
|
+
"@arethetypeswrong/cli": "0.18.5",
|
|
50
|
+
"@types/node": "26.4.0",
|
|
51
|
+
"publint": "0.3.24",
|
|
52
|
+
"tsdown": "0.22.14",
|
|
53
|
+
"typescript": "7.0.2",
|
|
54
|
+
"vitest": "4.1.11"
|
|
55
|
+
},
|
|
56
|
+
"engines": {
|
|
57
|
+
"node": ">=22.12"
|
|
58
|
+
},
|
|
59
|
+
"aiAgentSdk": {
|
|
60
|
+
"runtime": "node",
|
|
61
|
+
"coreApi": 1,
|
|
62
|
+
"roles": [
|
|
63
|
+
"mcp-client-transport"
|
|
64
|
+
]
|
|
65
|
+
},
|
|
66
|
+
"scripts": {
|
|
67
|
+
"build": "tsdown",
|
|
68
|
+
"clean": "node -e \"for(const p of ['dist','artifacts'])require('node:fs').rmSync(p,{recursive:true,force:true})\"",
|
|
69
|
+
"typecheck": "tsc --noEmit",
|
|
70
|
+
"test": "vitest run --config vitest.config.ts",
|
|
71
|
+
"pack": "pnpm pack --pack-destination artifacts",
|
|
72
|
+
"test:pack": "node ../../scripts/test-packed-node-capability.mts mcp-node",
|
|
73
|
+
"check:publint": "publint",
|
|
74
|
+
"check:types": "attw --profile esm-only --pack ."
|
|
75
|
+
}
|
|
76
|
+
}
|