@agentskit/mcp 0.3.8 → 0.4.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/README.md +55 -39
- package/dist/bin.cjs +111 -7
- package/dist/bin.cjs.map +1 -1
- package/dist/bin.js +9 -5
- package/dist/bin.js.map +1 -1
- package/dist/{chunk-5K3ZAG4X.js → chunk-DU5RLF44.js} +111 -7
- package/dist/chunk-DU5RLF44.js.map +1 -0
- package/dist/index.cjs +109 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -2
- package/dist/index.d.ts +24 -2
- package/dist/index.js +1 -1
- package/package.json +14 -14
- package/LICENSE +0 -21
- package/dist/chunk-5K3ZAG4X.js.map +0 -1
package/README.md
CHANGED
|
@@ -9,13 +9,13 @@ Profile: <code>major-package</code>
|
|
|
9
9
|
[](../../docs/STABILITY.md)
|
|
10
10
|
|
|
11
11
|
Expose AgentsKit tools as an [MCP](https://modelcontextprotocol.io) server — use
|
|
12
|
-
them from
|
|
12
|
+
them from Claude Desktop, Cursor, Windsurf, or any MCP host.
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
## Verified proof
|
|
16
16
|
|
|
17
17
|
- Package metadata and tests live under `packages/mcp/`.
|
|
18
|
-
-
|
|
18
|
+
- MCP package guide: https://www.agentskit.io/docs/agents/tools/mcp
|
|
19
19
|
- Stability map: [docs/STABILITY.md](../../docs/STABILITY.md)
|
|
20
20
|
|
|
21
21
|
## How this fits the ecosystem
|
|
@@ -27,41 +27,73 @@ them from Codex, Claude Code/Desktop, Cursor, Cline, Continue, or any MCP host.
|
|
|
27
27
|
- **Playbook**: use [playbook.agentskit.io](https://playbook.agentskit.io) for safe tool design, approvals, and agent handoff patterns.
|
|
28
28
|
- **AKOS**: run the same model with enterprise deployment, governance, and observability at [akos.agentskit.io](https://akos.agentskit.io).
|
|
29
29
|
|
|
30
|
-
Docs: [package guide](https://www.agentskit.io/docs/agents/tools/mcp) · [agent handoff](https://github.com/AgentsKit-io/agentskit/blob/main/llms.txt)
|
|
30
|
+
Docs: [MCP package guide](https://www.agentskit.io/docs/agents/tools/mcp) · [agent handoff](https://github.com/AgentsKit-io/agentskit/blob/main/llms.txt)
|
|
31
31
|
|
|
32
32
|
<!-- readme-command:install -->
|
|
33
33
|
```bash
|
|
34
|
-
npx -y @agentskit/mcp@0.3.
|
|
34
|
+
npx -y @agentskit/mcp@0.3.9 --tools fetch,search
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
Then point your MCP host at the command.
|
|
37
|
+
Then point your MCP host at the command. Claude Desktop, Cursor, Codex, and
|
|
38
|
+
OpenClaw all launch the same stdio server with host-specific configuration.
|
|
39
|
+
|
|
40
|
+
Claude Desktop or Cursor (`mcpServers` / `.cursor/mcp.json`):
|
|
38
41
|
|
|
39
42
|
```json
|
|
40
43
|
{
|
|
41
44
|
"mcpServers": {
|
|
42
|
-
"agentskit": { "command": "npx", "args": ["-y", "@agentskit/mcp@0.3.
|
|
45
|
+
"agentskit": { "command": "npx", "args": ["-y", "@agentskit/mcp@0.3.9", "--tools", "fetch,search"] }
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
48
|
```
|
|
46
49
|
|
|
47
|
-
|
|
50
|
+
Codex (`~/.codex/config.toml`):
|
|
51
|
+
|
|
52
|
+
```toml
|
|
53
|
+
[mcp_servers.agentskit]
|
|
54
|
+
command = "npx"
|
|
55
|
+
args = ["-y", "@agentskit/mcp@0.3.9", "--tools", "fetch,search"]
|
|
56
|
+
```
|
|
48
57
|
|
|
49
|
-
|
|
50
|
-
changes:
|
|
58
|
+
OpenClaw:
|
|
51
59
|
|
|
52
60
|
```bash
|
|
53
|
-
|
|
54
|
-
|
|
61
|
+
openclaw mcp add agentskit \
|
|
62
|
+
--command npx \
|
|
63
|
+
--arg -y \
|
|
64
|
+
--arg @agentskit/mcp@0.3.9 \
|
|
65
|
+
--arg --tools \
|
|
66
|
+
--arg fetch,search
|
|
67
|
+
openclaw mcp doctor agentskit --probe
|
|
68
|
+
```
|
|
55
69
|
|
|
56
|
-
|
|
57
|
-
|
|
70
|
+
Verify the server in each host with its MCP tool-list command before enabling
|
|
71
|
+
additional tools. Pi does not have a native MCP host path in this recipe; use
|
|
72
|
+
a Pi extension or package when a dedicated integration is available.
|
|
73
|
+
|
|
74
|
+
Codex (`~/.codex/config.toml`):
|
|
75
|
+
|
|
76
|
+
```toml
|
|
77
|
+
[mcp_servers.agentskit]
|
|
78
|
+
command = "npx"
|
|
79
|
+
args = ["-y", "@agentskit/mcp@0.3.9", "--tools", "fetch,search"]
|
|
58
80
|
```
|
|
59
81
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
82
|
+
OpenClaw:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
openclaw mcp add agentskit \
|
|
86
|
+
--command npx \
|
|
87
|
+
--arg -y \
|
|
88
|
+
--arg @agentskit/mcp@0.3.9 \
|
|
89
|
+
--arg --tools \
|
|
90
|
+
--arg fetch,search
|
|
91
|
+
openclaw mcp doctor agentskit --probe
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Verify the server in each host with its MCP tool-list command before enabling
|
|
95
|
+
additional tools. Pi does not have a native MCP host path in this recipe; use
|
|
96
|
+
a Pi extension or package when a dedicated integration is available.
|
|
65
97
|
|
|
66
98
|
## Flags
|
|
67
99
|
|
|
@@ -71,13 +103,6 @@ published-package smoke test.
|
|
|
71
103
|
| `--fs-root <dir>` | enable the filesystem tool, rooted at `<dir>` |
|
|
72
104
|
| `--sqlite <file>` | enable the sqlite query tool against `<file>` |
|
|
73
105
|
| `--allow-shell` | enable the shell tool (off by default — it runs commands) |
|
|
74
|
-
| `--agents <a,b>` | expose bounded, runnable registry agents as MCP tools |
|
|
75
|
-
| `--provider <id>` | provider for registry agents (default `openai`) |
|
|
76
|
-
| `--model <id>` | explicit provider model; required when no maintained default exists |
|
|
77
|
-
| `--max-steps <1-100>` | bound each delegated agent run (default `8`) |
|
|
78
|
-
| `--api-key <value>` | provider key; prefer `<PROVIDER>_API_KEY` to avoid process-list exposure |
|
|
79
|
-
| `--base-url <url>` | override a compatible provider endpoint |
|
|
80
|
-
| `--help` | print help to `stderr` without contaminating the protocol channel |
|
|
81
106
|
|
|
82
107
|
`stdout` is the MCP JSON-RPC channel; human output goes to `stderr`.
|
|
83
108
|
|
|
@@ -91,11 +116,6 @@ createAgentsKitMcpServer({ tools: [fetchUrl()] }) // stdio by default
|
|
|
91
116
|
```
|
|
92
117
|
|
|
93
118
|
Pass `transport` to use a custom MCP transport (e.g. in-memory for tests).
|
|
94
|
-
Server construction rejects malformed metadata, invalid or duplicate tool names,
|
|
95
|
-
and invalid transports with `AK_CONFIG_INVALID`. The published tool list and
|
|
96
|
-
top-level definition fields are snapshotted, and observer exceptions or rejected
|
|
97
|
-
promises cannot alter protocol behavior. Nested schemas remain trusted tool-owned
|
|
98
|
-
configuration.
|
|
99
119
|
|
|
100
120
|
## Expose whole agents (agents as MCP tools)
|
|
101
121
|
|
|
@@ -103,7 +123,7 @@ Run a registry agent server-side and expose it as a single MCP tool — the host
|
|
|
103
123
|
delegates a specialized job instead of orchestrating primitives:
|
|
104
124
|
|
|
105
125
|
```bash
|
|
106
|
-
npx
|
|
126
|
+
npx @agentskit/mcp@0.3.9 --agents legal-contract-reviewer,fintech-kyc-screener --provider openai
|
|
107
127
|
```
|
|
108
128
|
|
|
109
129
|
`--provider` covers the first-class adapters (openai, anthropic, gemini, ollama)
|
|
@@ -112,15 +132,15 @@ fireworks, openrouter, cerebras, kimi, huggingface, qwen, lmstudio, vllm, llamac
|
|
|
112
132
|
and any other OpenAI-compatible provider in the models.dev catalog. Key from
|
|
113
133
|
`--api-key` or `<PROVIDER>_API_KEY`; `--model` / `--base-url` optional.
|
|
114
134
|
|
|
115
|
-
Registry IDs are validated before URL construction. Each remote request is
|
|
116
|
-
abortable, defaults to a 10-second timeout, and is capped at 128 KiB. Registry
|
|
117
|
-
source is parsed as bounded text and is never executed.
|
|
118
|
-
|
|
119
135
|
```ts
|
|
120
136
|
import { createAgentTool } from '@agentskit/mcp'
|
|
121
137
|
createAgentsKitMcpServer({ tools: [createAgentTool({ id, description, systemPrompt, adapter })] })
|
|
122
138
|
```
|
|
123
139
|
|
|
140
|
+
Typed Registry projections use `fetchAgent` + `createTypedAgentTool`; their
|
|
141
|
+
input/output JSON Schemas are preserved. `fetchAgentSkill` intentionally
|
|
142
|
+
rejects typed projections so they cannot be flattened into a text tool.
|
|
143
|
+
|
|
124
144
|
## Quick start
|
|
125
145
|
|
|
126
146
|
<!-- readme-example:quickstart -->
|
|
@@ -139,10 +159,6 @@ await server.close()
|
|
|
139
159
|
- **Node.js 20+** and **TypeScript** strict mode
|
|
140
160
|
- Published as `@agentskit/mcp`
|
|
141
161
|
|
|
142
|
-
This package intentionally implements the MCP tools subset over stdio or an
|
|
143
|
-
injected transport. HTTP/WebSocket transports, resources, prompts, sampling,
|
|
144
|
-
authentication, rate limiting, and persistence are not built in.
|
|
145
|
-
|
|
146
162
|
## Contributing
|
|
147
163
|
|
|
148
164
|
See [CONTRIBUTING.md](../../CONTRIBUTING.md) and the monorepo [LICENSE](../../LICENSE).
|
package/dist/bin.cjs
CHANGED
|
@@ -6,6 +6,7 @@ var catalog = require('@agentskit/adapters/catalog');
|
|
|
6
6
|
var tools = require('@agentskit/tools');
|
|
7
7
|
var core = require('@agentskit/core');
|
|
8
8
|
var runtime = require('@agentskit/runtime');
|
|
9
|
+
var validation = require('@agentskit/tools/validation');
|
|
9
10
|
var mcp = require('@agentskit/tools/mcp');
|
|
10
11
|
|
|
11
12
|
var encoder = new TextEncoder();
|
|
@@ -90,12 +91,105 @@ function createAgentTool(config) {
|
|
|
90
91
|
};
|
|
91
92
|
return Object.freeze(tool);
|
|
92
93
|
}
|
|
94
|
+
function createTypedAgentTool(config) {
|
|
95
|
+
const id = assertToolName(config?.id, "typed agent tool id");
|
|
96
|
+
const description = assertNonEmptyString(config?.description, "typed agent tool description", 4096);
|
|
97
|
+
const systemPrompt = assertNonEmptyString(config?.systemPrompt, "typed agent tool systemPrompt", 65536);
|
|
98
|
+
const resultToolName = assertToolName(config?.resultToolName, "typed agent result tool name");
|
|
99
|
+
const maxTaskBytes = assertPositiveInteger(config.maxTaskBytes ?? 65536, "typed agent input", 1048576);
|
|
100
|
+
if (!isRecord(config?.adapter) || typeof config.adapter.createSource !== "function") {
|
|
101
|
+
throw new core.ConfigError({
|
|
102
|
+
code: core.ErrorCodes.AK_CONFIG_INVALID,
|
|
103
|
+
message: "typed agent tool adapter must implement createSource"
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
if (!isRecord(config.inputSchema) || !isRecord(config.outputSchema)) {
|
|
107
|
+
throw new core.ConfigError({
|
|
108
|
+
code: core.ErrorCodes.AK_CONFIG_INVALID,
|
|
109
|
+
message: "typed agent tool schemas must be JSON Schema objects"
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
const validate = validation.createAjvValidator({ rejectAdditionalProperties: true });
|
|
113
|
+
try {
|
|
114
|
+
validate(config.inputSchema, {});
|
|
115
|
+
validate(config.outputSchema, {});
|
|
116
|
+
} catch {
|
|
117
|
+
throw new core.ConfigError({
|
|
118
|
+
code: core.ErrorCodes.AK_CONFIG_INVALID,
|
|
119
|
+
message: "typed agent tool schemas must be valid JSON Schema"
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
const submit = {
|
|
123
|
+
name: resultToolName,
|
|
124
|
+
description: "Return the structured agent result.",
|
|
125
|
+
schema: config.outputSchema,
|
|
126
|
+
execute: async () => "recorded"
|
|
127
|
+
};
|
|
128
|
+
const skill = { name: id, description, systemPrompt };
|
|
129
|
+
const tool = {
|
|
130
|
+
name: id,
|
|
131
|
+
description,
|
|
132
|
+
schema: config.inputSchema,
|
|
133
|
+
execute: async (args) => {
|
|
134
|
+
const task = JSON.stringify(args);
|
|
135
|
+
if (new TextEncoder().encode(task).byteLength > maxTaskBytes) {
|
|
136
|
+
throw new core.ToolError({
|
|
137
|
+
code: core.ErrorCodes.AK_TOOL_INVALID_INPUT,
|
|
138
|
+
message: `typed agent input must not exceed ${maxTaskBytes} bytes`
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
const input = validate(config.inputSchema, args);
|
|
142
|
+
if (!input.valid) {
|
|
143
|
+
throw new core.ToolError({
|
|
144
|
+
code: core.ErrorCodes.AK_TOOL_INVALID_INPUT,
|
|
145
|
+
message: input.message ?? "typed agent input does not match its schema"
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
return runtime.invokeStructured({
|
|
149
|
+
adapter: config.adapter,
|
|
150
|
+
tool: submit,
|
|
151
|
+
task: `INPUT:
|
|
152
|
+
${task}`,
|
|
153
|
+
parse: (value) => {
|
|
154
|
+
const output = validate(config.outputSchema, value);
|
|
155
|
+
if (!output.valid) {
|
|
156
|
+
throw new core.ToolError({
|
|
157
|
+
code: core.ErrorCodes.AK_TOOL_INVALID_INPUT,
|
|
158
|
+
message: output.message ?? "typed agent output does not match its schema"
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
return value;
|
|
162
|
+
},
|
|
163
|
+
skill,
|
|
164
|
+
onConfirm: config.onConfirm,
|
|
165
|
+
maxSteps: config.maxSteps ?? 4
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
return Object.freeze(tool);
|
|
170
|
+
}
|
|
93
171
|
|
|
94
172
|
// src/registry-fetch.ts
|
|
95
173
|
var HOSTED = "https://registry.agentskit.io/r";
|
|
96
174
|
var RAW = "https://raw.githubusercontent.com/AgentsKit-io/agentskit-registry/main";
|
|
97
175
|
var REGISTRY_ID = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
|
|
176
|
+
var TOOL_NAME2 = /^[A-Za-z0-9_.-]{1,128}$/;
|
|
98
177
|
var isRecord2 = (input) => input !== null && typeof input === "object" && !Array.isArray(input);
|
|
178
|
+
var readTypedMcpProjection = (input) => {
|
|
179
|
+
const projections = input.projections;
|
|
180
|
+
if (!isRecord2(projections)) return void 0;
|
|
181
|
+
const mcp = projections.mcp;
|
|
182
|
+
if (!isRecord2(mcp) || mcp.mode === void 0) return void 0;
|
|
183
|
+
if (mcp.mode !== "typed") return void 0;
|
|
184
|
+
if (!isRecord2(mcp.inputSchema) || !isRecord2(mcp.outputSchema)) return null;
|
|
185
|
+
if (typeof mcp.resultToolName !== "string" || !TOOL_NAME2.test(mcp.resultToolName)) return null;
|
|
186
|
+
return {
|
|
187
|
+
inputSchema: mcp.inputSchema,
|
|
188
|
+
mode: "typed",
|
|
189
|
+
outputSchema: mcp.outputSchema,
|
|
190
|
+
resultToolName: mcp.resultToolName
|
|
191
|
+
};
|
|
192
|
+
};
|
|
99
193
|
var boundedString = (input, maximum) => {
|
|
100
194
|
if (typeof input !== "string" || input.trim().length === 0) return null;
|
|
101
195
|
return new TextEncoder().encode(input).byteLength <= maximum ? input.trim() : null;
|
|
@@ -160,7 +254,7 @@ var requestJson = async (url, fetchImpl, options) => {
|
|
|
160
254
|
return null;
|
|
161
255
|
}
|
|
162
256
|
};
|
|
163
|
-
async function
|
|
257
|
+
async function fetchAgent(id, fetchImpl = globalThis.fetch, options = {}) {
|
|
164
258
|
if (!REGISTRY_ID.test(id) || typeof fetchImpl !== "function") return null;
|
|
165
259
|
const timeoutMs = options.timeoutMs ?? 1e4;
|
|
166
260
|
const maxResponseBytes = options.maxResponseBytes ?? 131072;
|
|
@@ -168,17 +262,22 @@ async function fetchAgentSkill(id, fetchImpl = globalThis.fetch, options = {}) {
|
|
|
168
262
|
const bounds = { maxResponseBytes, signal: options.signal, timeoutMs };
|
|
169
263
|
const hosted = await requestJson(`${HOSTED}/${id}.json`, fetchImpl, bounds);
|
|
170
264
|
if (isRecord2(hosted)) {
|
|
265
|
+
const typed2 = readTypedMcpProjection(hosted);
|
|
266
|
+
if (typed2 === null) return null;
|
|
171
267
|
if (hosted.skill === null) return null;
|
|
172
268
|
if (isRecord2(hosted.skill)) {
|
|
173
269
|
const systemPrompt2 = boundedString(hosted.skill.systemPrompt, 65536);
|
|
174
270
|
if (systemPrompt2) {
|
|
175
271
|
const description = boundedString(hosted.description, 4096) ?? id;
|
|
272
|
+
if (typed2) return Object.freeze({ description, id, systemPrompt: systemPrompt2, ...typed2 });
|
|
176
273
|
return Object.freeze({ description, id, systemPrompt: systemPrompt2 });
|
|
177
274
|
}
|
|
178
275
|
}
|
|
179
276
|
}
|
|
180
277
|
const meta = await requestJson(`${RAW}/registry/${id}/meta.json`, fetchImpl, bounds);
|
|
181
278
|
if (!isRecord2(meta)) return null;
|
|
279
|
+
const typed = readTypedMcpProjection(meta);
|
|
280
|
+
if (typed === null) return null;
|
|
182
281
|
const source = await requestText(`${RAW}/registry/${id}/agent.ts`, fetchImpl, bounds);
|
|
183
282
|
if (!source) return null;
|
|
184
283
|
const match = source.match(/systemPrompt:\s*`((?:\\.|[^`\\])*)`/);
|
|
@@ -188,11 +287,12 @@ async function fetchAgentSkill(id, fetchImpl = globalThis.fetch, options = {}) {
|
|
|
188
287
|
65536
|
|
189
288
|
);
|
|
190
289
|
if (!systemPrompt) return null;
|
|
191
|
-
|
|
290
|
+
const skill = {
|
|
192
291
|
id,
|
|
193
292
|
description: boundedString(meta.description, 4096) ?? id,
|
|
194
293
|
systemPrompt
|
|
195
|
-
}
|
|
294
|
+
};
|
|
295
|
+
return Object.freeze(typed ? { ...skill, ...typed } : skill);
|
|
196
296
|
}
|
|
197
297
|
|
|
198
298
|
// src/index.ts
|
|
@@ -414,14 +514,18 @@ var runMcpCli = async (argv, dependencies = {}) => {
|
|
|
414
514
|
if (parsed.options.agents.length > 0) {
|
|
415
515
|
const adapter = resolveAdapter(parsed.options, dependencies.env ?? process.env, warn2);
|
|
416
516
|
if (adapter) {
|
|
417
|
-
const
|
|
517
|
+
const fetch = dependencies.fetchAgent ?? dependencies.fetchSkill ?? fetchAgent;
|
|
418
518
|
for (const id of parsed.options.agents) {
|
|
419
|
-
const
|
|
420
|
-
if (!
|
|
519
|
+
const agent = await fetch(id).catch(() => null);
|
|
520
|
+
if (!agent) {
|
|
421
521
|
warn2(`skipping agent "${id}": not found or not runnable`);
|
|
422
522
|
continue;
|
|
423
523
|
}
|
|
424
|
-
|
|
524
|
+
try {
|
|
525
|
+
tools.push("mode" in agent && agent.mode === "typed" ? createTypedAgentTool({ ...agent, adapter, maxSteps: parsed.options.maxSteps }) : createAgentTool({ ...agent, adapter, maxSteps: parsed.options.maxSteps }));
|
|
526
|
+
} catch {
|
|
527
|
+
warn2(`skipping agent "${id}": invalid projection`);
|
|
528
|
+
}
|
|
425
529
|
}
|
|
426
530
|
}
|
|
427
531
|
}
|
package/dist/bin.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/validation.ts","../src/agent-tool.ts","../src/registry-fetch.ts","../src/index.ts","../src/cli.ts","../src/bin.ts"],"names":["ConfigError","ErrorCodes","ToolError","runtime","createRuntime","isRecord","systemPrompt","createStdioTransport","createMcpServer","anthropic","cerebras","cohere","deepseek","fireworks","gemini","grok","groq","huggingface","kimi","llamacpp","lmstudio","mistral","openai","openrouter","qwen","together","vllm","ollama","warn","tools","fetchUrl","webSearch","filesystem","sqliteQueryTool","shell","dispatchFromCatalog"],"mappings":";;;;;;;;;;AAEA,IAAM,OAAA,GAAU,IAAI,WAAA,EAAY;AAChC,IAAM,SAAA,GAAY,mBAAA;AAElB,IAAM,OAAA,GAAU,CAAC,OAAA,KACf,IAAIA,gBAAA,CAAY,EAAE,IAAA,EAAMC,eAAA,CAAW,iBAAA,EAAmB,OAAA,EAAS,CAAA;AAE1D,IAAM,oBAAA,GAAuB,CAClC,KAAA,EACA,KAAA,EACA,QAAA,KACW;AACX,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,MAAM,IAAA,EAAK,CAAE,WAAW,CAAA,EAAG;AAC1D,IAAA,MAAM,OAAA,CAAQ,CAAA,EAAG,KAAK,CAAA,2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AM,KAAA,CAAM,KAAA,IAAS,SAAS,CAAA,CAAE,CAAA;AAAA,MACzG;AAAA,KACD,CAAA;AAAA,EACH,CAAA,CAAA,MAAQ;AACN,IAAAA,MAAK,4BAA4B,CAAA;AACjC,IAAA,OAAO,EAAE,QAAA,EAAU,CAAA,EAAG,MAAA,EAAQ,UAAA,EAAW;AAAA,EAC3C;AACA,EAAA,MAAM,YAAY,KAAA,CAAM,GAAA,CAAI,CAAC,IAAA,KAAS,KAAK,IAAI,CAAA;AAC/C,EAAAA,KAAAA,CAAK,WAAW,SAAA,CAAU,MAAM,wBAAwB,SAAA,CAAU,IAAA,CAAK,IAAI,CAAC,CAAA,CAAA,CAAG,CAAA;AAC/E,EAAA,OAAO,EAAE,QAAA,EAAU,CAAA,EAAG,MAAA,EAAQ,MAAA,EAAQ,WAAW,SAAA,EAAU;AAC7D,CAAA;;;AC3PA,IAAM,IAAA,GAAO,CAAC,OAAA,KAA0B;AACtC,EAAA,OAAA,CAAQ,MAAA,CAAO,KAAA,CAAM,CAAA,eAAA,EAAkB,OAAO;AAAA,CAAI,CAAA;AACpD,CAAA;AAEA,KAAK,SAAA,CAAU,OAAA,CAAQ,IAAA,CAAK,KAAA,CAAM,CAAC,CAAA,EAAG,EAAE,IAAA,EAAM,CAAA,CAAE,IAAA,CAAK,CAAC,MAAA,KAAW;AAC/D,EAAA,OAAA,CAAQ,WAAW,MAAA,CAAO,QAAA;AAC5B,CAAC,CAAA,CAAE,MAAM,MAAM;AACb,EAAA,IAAA,CAAK,4BAA4B,CAAA;AACjC,EAAA,OAAA,CAAQ,QAAA,GAAW,CAAA;AACrB,CAAC,CAAA","file":"bin.cjs","sourcesContent":["import { ConfigError, ErrorCodes } from '@agentskit/core'\n\nconst encoder = new TextEncoder()\nconst TOOL_NAME = /^[A-Za-z0-9_.-]+$/\n\nconst invalid = (message: string): ConfigError =>\n new ConfigError({ code: ErrorCodes.AK_CONFIG_INVALID, message })\n\nexport const assertNonEmptyString = (\n input: unknown,\n field: string,\n maxBytes: number,\n): string => {\n if (typeof input !== 'string' || input.trim().length === 0) {\n throw invalid(`${field} must be a non-empty string`)\n }\n if (encoder.encode(input).byteLength > maxBytes) {\n throw invalid(`${field} must not exceed ${maxBytes} bytes`)\n }\n return input.trim()\n}\n\nexport const assertToolName = (input: unknown, field = 'tool name'): string => {\n const value = assertNonEmptyString(input, field, 128)\n if (!TOOL_NAME.test(value)) {\n throw invalid(`${field} may contain only ASCII letters, digits, underscore, hyphen, and dot`)\n }\n return value\n}\n\nexport const assertPositiveInteger = (\n input: unknown,\n field: string,\n maximum: number,\n): number => {\n if (!Number.isSafeInteger(input) || (input as number) < 1 || (input as number) > maximum) {\n throw invalid(`${field} must be a safe integer between 1 and ${maximum}`)\n }\n return input as number\n}\n\nexport const isRecord = (input: unknown): input is Record<string, unknown> => {\n if (input === null || typeof input !== 'object' || Array.isArray(input)) return false\n try {\n const prototype = Object.getPrototypeOf(input) as object | null\n return prototype === Object.prototype || prototype === null\n } catch {\n return false\n }\n}\n","import {\n ConfigError,\n ErrorCodes,\n ToolError,\n type AdapterFactory,\n type SkillDefinition,\n type ToolDefinition,\n} from '@agentskit/core'\nimport { createRuntime } from '@agentskit/runtime'\nimport { assertNonEmptyString, assertPositiveInteger, assertToolName, isRecord } from './validation'\n\nexport interface AgentToolConfig {\n /** Tool name exposed to the MCP host (the agent id). */\n id: string\n description: string\n /** The agent's system prompt (its skill). */\n systemPrompt: string\n /** Model adapter the agent runs on (server-side). */\n adapter: AdapterFactory\n maxSteps?: number\n /** Maximum UTF-8 bytes accepted in one task. Default 65536. */\n maxTaskBytes?: number\n}\n\n/**\n * Wrap a whole agent as a single MCP tool. The MCP host calls it with a `task`\n * string; the agent runs server-side (its own skill + reasoning loop on the\n * provided adapter) and returns the result. This is \"agents as MCP tools\" — the\n * host delegates a specialized job rather than orchestrating primitives.\n */\nexport function createAgentTool(config: AgentToolConfig): ToolDefinition {\n const id = assertToolName(config?.id, 'agent tool id')\n const description = assertNonEmptyString(config?.description, 'agent tool description', 4096)\n const systemPrompt = assertNonEmptyString(config?.systemPrompt, 'agent tool systemPrompt', 65_536)\n if (!isRecord(config?.adapter) || typeof config.adapter.createSource !== 'function') {\n throw new ConfigError({\n code: ErrorCodes.AK_CONFIG_INVALID,\n message: 'agent tool adapter must implement createSource',\n })\n }\n const maxSteps = assertPositiveInteger(config.maxSteps ?? 8, 'agent tool maxSteps', 100)\n const maxTaskBytes = assertPositiveInteger(config.maxTaskBytes ?? 65_536, 'agent tool maxTaskBytes', 1_048_576)\n const skill: SkillDefinition = {\n name: id,\n description,\n systemPrompt,\n }\n const tool: ToolDefinition = {\n name: id,\n description,\n schema: {\n type: 'object',\n properties: { task: { type: 'string', description: 'The task or input for the agent.' } },\n required: ['task'],\n additionalProperties: false,\n },\n execute: async (args: Record<string, unknown>) => {\n if (typeof args.task !== 'string' || args.task.trim().length === 0) {\n throw new ToolError({\n code: ErrorCodes.AK_TOOL_INVALID_INPUT,\n message: 'agent tool task must be a non-empty string',\n })\n }\n if (new TextEncoder().encode(args.task).byteLength > maxTaskBytes) {\n throw new ToolError({\n code: ErrorCodes.AK_TOOL_INVALID_INPUT,\n message: `agent tool task must not exceed ${maxTaskBytes} bytes`,\n })\n }\n const runtime = createRuntime({ adapter: config.adapter, maxSteps })\n const result = await runtime.run(args.task, { skill })\n return { content: result.content, steps: result.steps }\n },\n }\n return Object.freeze(tool)\n}\n","const HOSTED = 'https://registry.agentskit.io/r'\nconst RAW = 'https://raw.githubusercontent.com/AgentsKit-io/agentskit-registry/main'\nconst REGISTRY_ID = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/\n\nexport interface FetchedAgentSkill {\n id: string\n description: string\n systemPrompt: string\n}\n\nexport interface FetchAgentSkillOptions {\n /** Per-request timeout. Default 10000 ms. */\n timeoutMs?: number\n /** Maximum UTF-8 response bytes. Default 131072. */\n maxResponseBytes?: number\n signal?: AbortSignal\n}\n\nconst isRecord = (input: unknown): input is Record<string, unknown> =>\n input !== null && typeof input === 'object' && !Array.isArray(input)\n\nconst boundedString = (input: unknown, maximum: number): string | null => {\n if (typeof input !== 'string' || input.trim().length === 0) return null\n return new TextEncoder().encode(input).byteLength <= maximum ? input.trim() : null\n}\n\nconst readBounded = async (response: Response, maximum: number): Promise<string | null> => {\n const declared = Number(response.headers.get('content-length'))\n if (Number.isFinite(declared) && declared > maximum) return null\n if (!response.body) return ''\n\n const reader = response.body.getReader()\n const decoder = new TextDecoder()\n let bytes = 0\n let text = ''\n while (true) {\n const chunk = await reader.read()\n if (chunk.done) break\n bytes += chunk.value.byteLength\n if (bytes > maximum) {\n await reader.cancel().catch(() => undefined)\n return null\n }\n text += decoder.decode(chunk.value, { stream: true })\n }\n return text + decoder.decode()\n}\n\nconst requestText = async (\n url: string,\n fetchImpl: typeof fetch,\n options: Required<Pick<FetchAgentSkillOptions, 'maxResponseBytes' | 'timeoutMs'>> &\n Pick<FetchAgentSkillOptions, 'signal'>,\n): Promise<string | null> => {\n if (options.signal?.aborted) return null\n const controller = new AbortController()\n let resolveAbort: ((value: null) => void) | undefined\n const aborted = new Promise<null>((resolve) => {\n resolveAbort = resolve\n })\n const abort = (): void => {\n controller.abort()\n resolveAbort?.(null)\n }\n options.signal?.addEventListener('abort', abort, { once: true })\n let timer: ReturnType<typeof setTimeout> | undefined\n try {\n const request = (async (): Promise<string | null> => {\n const response = await fetchImpl(url, { signal: controller.signal })\n if (!response.ok) return null\n return readBounded(response, options.maxResponseBytes)\n })().catch(() => null)\n const timeout = new Promise<null>((resolve) => {\n timer = setTimeout(() => {\n controller.abort()\n resolve(null)\n }, options.timeoutMs)\n })\n return await Promise.race([request, timeout, aborted])\n } finally {\n if (timer !== undefined) clearTimeout(timer)\n options.signal?.removeEventListener('abort', abort)\n }\n}\n\nconst requestJson = async (\n url: string,\n fetchImpl: typeof fetch,\n options: Required<Pick<FetchAgentSkillOptions, 'maxResponseBytes' | 'timeoutMs'>> &\n Pick<FetchAgentSkillOptions, 'signal'>,\n): Promise<unknown | null> => {\n const text = await requestText(url, fetchImpl, options)\n if (text === null) return null\n try {\n return JSON.parse(text) as unknown\n } catch {\n return null\n }\n}\n\nexport async function fetchAgentSkill(\n id: string,\n fetchImpl: typeof fetch = globalThis.fetch,\n options: FetchAgentSkillOptions = {},\n): Promise<FetchedAgentSkill | null> {\n if (!REGISTRY_ID.test(id) || typeof fetchImpl !== 'function') return null\n const timeoutMs = options.timeoutMs ?? 10_000\n const maxResponseBytes = options.maxResponseBytes ?? 131_072\n if (\n !Number.isSafeInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 120_000 ||\n !Number.isSafeInteger(maxResponseBytes) || maxResponseBytes < 1 || maxResponseBytes > 1_048_576\n ) return null\n const bounds = { maxResponseBytes, signal: options.signal, timeoutMs }\n\n const hosted = await requestJson(`${HOSTED}/${id}.json`, fetchImpl, bounds)\n if (isRecord(hosted)) {\n if (hosted.skill === null) return null\n if (isRecord(hosted.skill)) {\n const systemPrompt = boundedString(hosted.skill.systemPrompt, 65_536)\n if (systemPrompt) {\n const description = boundedString(hosted.description, 4096) ?? id\n return Object.freeze({ description, id, systemPrompt })\n }\n }\n }\n\n const meta = await requestJson(`${RAW}/registry/${id}/meta.json`, fetchImpl, bounds)\n if (!isRecord(meta)) return null\n const source = await requestText(`${RAW}/registry/${id}/agent.ts`, fetchImpl, bounds)\n if (!source) return null\n const match = source.match(/systemPrompt:\\s*`((?:\\\\.|[^`\\\\])*)`/)\n if (!match) return null\n const systemPrompt = boundedString(\n match[1].replace(/\\\\`/g, '`').replace(/\\\\\\$\\{/g, '${'),\n 65_536,\n )\n if (!systemPrompt) return null\n return Object.freeze({\n id,\n description: boundedString(meta.description, 4096) ?? id,\n systemPrompt,\n })\n}\n","import { ConfigError, ErrorCodes, type ToolDefinition } from '@agentskit/core'\nimport {\n createMcpServer,\n createStdioTransport,\n type McpServer,\n type McpTransport,\n type StdioLikeProcess,\n} from '@agentskit/tools/mcp'\nimport { assertNonEmptyString, assertToolName, isRecord } from './validation'\n\nexport interface AgentsKitMcpServerOptions {\n /** AgentsKit tools to expose to the MCP host. */\n tools: ToolDefinition[]\n serverInfo?: { name: string; version: string }\n /** Observability hook (call / error / list). Logs must NOT go to stdout — it is the MCP channel. */\n onEvent?: (event: { type: 'call' | 'error' | 'list'; tool?: string; error?: string }) => void\n /**\n * Transport override. Defaults to stdio over the current process (the form\n * Codex / Claude Code / Cursor launch). Inject a custom transport for tests.\n */\n transport?: McpTransport\n}\n\n/**\n * Adapt the current Node process to the `StdioLikeProcess` the transport expects:\n * the server RECEIVES JSON-RPC on stdin and SENDS on stdout.\n */\nexport function processStdio(): StdioLikeProcess {\n return {\n stdin: { write: (chunk: string) => void process.stdout.write(chunk) },\n stdout: {\n on: (_event: 'data', cb: (chunk: Buffer | string) => void) => void process.stdin.on('data', cb),\n off: (_event: 'data', cb: (chunk: Buffer | string) => void) => void process.stdin.off('data', cb),\n },\n on: (event: 'exit' | 'close', cb: () => void) =>\n void process.on(event === 'close' ? 'beforeExit' : 'exit', cb),\n }\n}\n\n/**\n * Expose a set of AgentsKit tools as an MCP server (over stdio by default), so\n * any MCP host — Codex, Claude Code, Cursor — can call them.\n */\nexport function createAgentsKitMcpServer(options: AgentsKitMcpServerOptions): McpServer {\n if (!isRecord(options) || !Array.isArray(options.tools)) {\n throw new ConfigError({\n code: ErrorCodes.AK_CONFIG_INVALID,\n message: 'MCP server options must include a tools array',\n })\n }\n\n const names = new Set<string>()\n const tools = options.tools.map((tool, index) => {\n if (!isRecord(tool)) {\n throw new ConfigError({\n code: ErrorCodes.AK_CONFIG_INVALID,\n message: `tools[${index}] must be a tool definition`,\n })\n }\n const name = assertToolName(tool.name, `tools[${index}].name`)\n if (names.has(name)) {\n throw new ConfigError({\n code: ErrorCodes.AK_CONFIG_INVALID,\n message: `tool names must be unique; duplicate \"${name}\"`,\n })\n }\n names.add(name)\n return Object.freeze({ ...tool, name }) as ToolDefinition\n })\n\n const serverInfo = options.serverInfo === undefined\n ? { name: 'agentskit-mcp', version: '1.0.0' }\n : {\n name: assertNonEmptyString(options.serverInfo?.name, 'serverInfo.name', 128),\n version: assertNonEmptyString(options.serverInfo?.version, 'serverInfo.version', 64),\n }\n\n if (\n options.transport !== undefined &&\n (!isRecord(options.transport) ||\n typeof options.transport.send !== 'function' ||\n typeof options.transport.onMessage !== 'function')\n ) {\n throw new ConfigError({\n code: ErrorCodes.AK_CONFIG_INVALID,\n message: 'transport must implement send and onMessage',\n })\n }\n\n const onEvent = options.onEvent === undefined\n ? undefined\n : (event: Parameters<NonNullable<AgentsKitMcpServerOptions['onEvent']>>[0]): void => {\n try {\n const delivered = (options.onEvent as (value: typeof event) => unknown)(Object.freeze({ ...event }))\n if (delivered !== null && (typeof delivered === 'object' || typeof delivered === 'function')) {\n const then = (delivered as { then?: unknown }).then\n if (typeof then === 'function') void Promise.resolve(delivered).catch(() => undefined)\n }\n } catch {\n // Observation must not alter protocol behavior.\n }\n }\n\n const transport = options.transport ?? createStdioTransport(processStdio())\n return createMcpServer({\n transport,\n tools,\n serverInfo,\n onEvent,\n })\n}\n\nexport { createAgentTool, type AgentToolConfig } from './agent-tool'\nexport {\n fetchAgentSkill,\n type FetchedAgentSkill,\n type FetchAgentSkillOptions,\n} from './registry-fetch'\nexport type { McpServer, McpTransport } from '@agentskit/tools/mcp'\n","import type { AdapterFactory, ToolDefinition } from '@agentskit/core'\nimport {\n anthropic,\n cerebras,\n cohere,\n deepseek,\n fireworks,\n gemini,\n grok,\n groq,\n huggingface,\n kimi,\n llamacpp,\n lmstudio,\n mistral,\n ollama,\n openai,\n openrouter,\n qwen,\n together,\n vllm,\n} from '@agentskit/adapters'\nimport { dispatchFromCatalog } from '@agentskit/adapters/catalog'\nimport { fetchUrl, filesystem, shell, sqliteQueryTool, webSearch } from '@agentskit/tools'\nimport type { McpServer } from '@agentskit/tools/mcp'\nimport { createAgentTool } from './agent-tool'\nimport { createAgentsKitMcpServer } from './index'\nimport { fetchAgentSkill, type FetchedAgentSkill } from './registry-fetch'\n\nconst VALUE_FLAGS = new Set([\n '--agents', '--api-key', '--base-url', '--fs-root', '--max-steps', '--model',\n '--provider', '--sqlite', '--tools',\n])\nconst BOOLEAN_FLAGS = new Set(['--allow-shell', '--help'])\nconst TOOL_IDS = new Set(['fetch', 'filesystem', 'search', 'shell', 'sqlite'])\n\nexport interface McpCliOptions {\n agents: string[]\n allowShell: boolean\n apiKey?: string\n baseUrl?: string\n fsRoot?: string\n help: boolean\n maxSteps: number\n model?: string\n provider: string\n sqlite?: string\n tools: string[]\n}\n\nexport type McpCliParseResult =\n | { message: string; status: 'rejected' }\n | { options: McpCliOptions; status: 'parsed' }\n\nconst csv = (input: string): string[] =>\n [...new Set(input.split(',').map((value) => value.trim()).filter(Boolean))]\n\nexport const parseMcpCliArgs = (argv: readonly string[]): McpCliParseResult => {\n const values = new Map<string, string>()\n const booleans = new Set<string>()\n for (let index = 0; index < argv.length; index += 1) {\n const argument = argv[index]!\n if (BOOLEAN_FLAGS.has(argument)) {\n if (booleans.has(argument)) return { message: `duplicate flag: ${argument}`, status: 'rejected' }\n booleans.add(argument)\n continue\n }\n if (!VALUE_FLAGS.has(argument)) return { message: `unknown argument: ${argument}`, status: 'rejected' }\n if (values.has(argument)) return { message: `duplicate flag: ${argument}`, status: 'rejected' }\n const value = argv[index + 1]\n if (value === undefined || value.startsWith('--')) {\n return { message: `missing value for ${argument}`, status: 'rejected' }\n }\n values.set(argument, value)\n index += 1\n }\n\n const tools = values.has('--tools') ? csv(values.get('--tools')!) : ['fetch', 'search']\n const unknownTool = tools.find((tool) => !TOOL_IDS.has(tool))\n if (unknownTool) return { message: `unknown tool: ${unknownTool}`, status: 'rejected' }\n const agents = values.has('--agents') ? csv(values.get('--agents')!) : []\n const maxStepsText = values.get('--max-steps') ?? '8'\n const maxSteps = Number(maxStepsText)\n if (!Number.isSafeInteger(maxSteps) || maxSteps < 1 || maxSteps > 100) {\n return { message: '--max-steps must be a safe integer between 1 and 100', status: 'rejected' }\n }\n\n return {\n options: {\n agents,\n allowShell: booleans.has('--allow-shell'),\n apiKey: values.get('--api-key'),\n baseUrl: values.get('--base-url'),\n fsRoot: values.get('--fs-root'),\n help: booleans.has('--help'),\n maxSteps,\n model: values.get('--model'),\n provider: (values.get('--provider') ?? 'openai').toLowerCase(),\n sqlite: values.get('--sqlite'),\n tools,\n },\n status: 'parsed',\n }\n}\n\ntype KeyedFactory = (config: { apiKey: string; baseUrl?: string; model: string }) => AdapterFactory\ntype LocalFactory = (config: { baseUrl?: string; model: string }) => AdapterFactory\n\nconst KEYED: Record<string, KeyedFactory> = {\n anthropic, cerebras, cohere, deepseek, fireworks, gemini, grok, groq,\n huggingface, kimi, llamacpp, lmstudio, mistral, openai, openrouter, qwen,\n together, vllm,\n}\nconst LOCAL: Record<string, LocalFactory> = { ollama }\nconst LOCAL_COMPAT = new Set(['llamacpp', 'lmstudio', 'vllm'])\nconst DEFAULT_MODEL: Record<string, string> = {\n anthropic: 'claude-sonnet-4-6',\n deepseek: 'deepseek-chat',\n gemini: 'gemini-2.0-flash',\n grok: 'grok-2',\n groq: 'openai/gpt-oss-120b',\n mistral: 'mistral-large-latest',\n ollama: 'llama3',\n openai: 'gpt-4o',\n}\n\nexport interface McpCliDependencies {\n createServer?: typeof createAgentsKitMcpServer\n env?: Readonly<Record<string, string | undefined>>\n fetchSkill?: (id: string) => Promise<FetchedAgentSkill | null>\n warn?: (message: string) => void\n}\n\nexport type McpCliRunResult =\n | { exitCode: 0; server: McpServer; status: 'started'; toolNames: string[] }\n | { exitCode: 0; status: 'help' }\n | { exitCode: 1; status: 'rejected' }\n\nexport const MCP_CLI_HELP = [\n 'Usage: agentskit-mcp [options]',\n '--tools <fetch,search,filesystem,shell,sqlite>',\n '--agents <registry-ids> --provider <provider> --model <model>',\n '--fs-root <dir> --sqlite <file> --allow-shell',\n].join('\\n')\n\nconst buildPrimitiveTools = (options: McpCliOptions, warn: (message: string) => void): ToolDefinition[] => {\n const tools: ToolDefinition[] = []\n if (options.tools.includes('fetch')) tools.push(fetchUrl())\n if (options.tools.includes('search')) tools.push(webSearch())\n if (options.tools.includes('filesystem')) {\n if (options.fsRoot) tools.push(...filesystem({ basePath: options.fsRoot }))\n else warn('skipping \"filesystem\": pass --fs-root <dir>')\n }\n if (options.tools.includes('sqlite')) {\n if (options.sqlite) tools.push(sqliteQueryTool({ path: options.sqlite }))\n else warn('skipping \"sqlite\": pass --sqlite <file>')\n }\n if (options.tools.includes('shell')) {\n if (options.allowShell) tools.push(shell())\n else warn('skipping \"shell\": pass --allow-shell (runs commands)')\n }\n return tools\n}\n\nconst resolveAdapter = (\n options: McpCliOptions,\n env: Readonly<Record<string, string | undefined>>,\n warn: (message: string) => void,\n): AdapterFactory | null => {\n const model = options.model ?? DEFAULT_MODEL[options.provider]\n if (!model) {\n warn(`--agents needs a model for \"${options.provider}\": pass --model`)\n return null\n }\n const local = LOCAL[options.provider]\n if (local) return local({ baseUrl: options.baseUrl, model })\n\n const envName = `${options.provider.toUpperCase().replace(/-/g, '_')}_API_KEY`\n const apiKey = options.apiKey ?? env[envName] ?? (LOCAL_COMPAT.has(options.provider) ? 'local' : undefined)\n if (!apiKey) {\n warn(`--agents needs a key for \"${options.provider}\": pass --api-key or set ${envName}`)\n return null\n }\n const keyed = KEYED[options.provider]\n if (keyed) return keyed({ apiKey, baseUrl: options.baseUrl, model })\n try {\n return dispatchFromCatalog({ apiKey, baseUrl: options.baseUrl, model, provider: options.provider })\n } catch {\n warn(`unknown or incompatible provider \"${options.provider}\"`)\n return null\n }\n}\n\nexport const runMcpCli = async (\n argv: readonly string[],\n dependencies: McpCliDependencies = {},\n): Promise<McpCliRunResult> => {\n const warn = dependencies.warn ?? (() => undefined)\n const parsed = parseMcpCliArgs(argv)\n if (parsed.status === 'rejected') {\n warn(parsed.message)\n return { exitCode: 1, status: 'rejected' }\n }\n if (parsed.options.help) {\n warn(MCP_CLI_HELP)\n return { exitCode: 0, status: 'help' }\n }\n\n const tools = buildPrimitiveTools(parsed.options, warn)\n if (parsed.options.agents.length > 0) {\n const adapter = resolveAdapter(parsed.options, dependencies.env ?? process.env, warn)\n if (adapter) {\n const fetchSkill = dependencies.fetchSkill ?? fetchAgentSkill\n for (const id of parsed.options.agents) {\n const skill = await fetchSkill(id).catch(() => null)\n if (!skill) {\n warn(`skipping agent \"${id}\": not found or not runnable`)\n continue\n }\n tools.push(createAgentTool({ ...skill, adapter, maxSteps: parsed.options.maxSteps }))\n }\n }\n }\n\n if (tools.length === 0) {\n warn('no tools or agents enabled — nothing to serve')\n return { exitCode: 1, status: 'rejected' }\n }\n const seen = new Set<string>()\n const duplicate = tools.find((tool) => {\n if (seen.has(tool.name)) return true\n seen.add(tool.name)\n return false\n })\n if (duplicate) {\n warn(`duplicate tool name: ${duplicate.name}`)\n return { exitCode: 1, status: 'rejected' }\n }\n const createServer = dependencies.createServer ?? createAgentsKitMcpServer\n let server: McpServer\n try {\n server = createServer({\n tools,\n onEvent: (event) => {\n if (event.type === 'error') warn(`tool error (${event.tool ?? 'unknown'}): ${event.error ?? 'unknown'}`)\n },\n })\n } catch {\n warn('failed to start MCP server')\n return { exitCode: 1, status: 'rejected' }\n }\n const toolNames = tools.map((tool) => tool.name)\n warn(`serving ${toolNames.length} item(s) over stdio (${toolNames.join(', ')})`)\n return { exitCode: 0, server, status: 'started', toolNames }\n}\n","#!/usr/bin/env node\nimport { runMcpCli } from './cli'\n\nconst warn = (message: string): void => {\n process.stderr.write(`agentskit-mcp: ${message}\\n`)\n}\n\nvoid runMcpCli(process.argv.slice(2), { warn }).then((result) => {\n process.exitCode = result.exitCode\n}).catch(() => {\n warn('unexpected startup failure')\n process.exitCode = 1\n})\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/validation.ts","../src/agent-tool.ts","../src/registry-fetch.ts","../src/index.ts","../src/cli.ts","../src/bin.ts"],"names":["ConfigError","ErrorCodes","ToolError","runtime","createRuntime","createAjvValidator","invokeStructured","TOOL_NAME","isRecord","typed","systemPrompt","createStdioTransport","createMcpServer","anthropic","cerebras","cohere","deepseek","fireworks","gemini","grok","groq","huggingface","kimi","llamacpp","lmstudio","mistral","openai","openrouter","qwen","together","vllm","ollama","warn","tools","fetchUrl","webSearch","filesystem","sqliteQueryTool","shell","dispatchFromCatalog"],"mappings":";;;;;;;;;;;AAEA,IAAM,OAAA,GAAU,IAAI,WAAA,EAAY;AAChC,IAAM,SAAA,GAAY,mBAAA;AAElB,IAAM,OAAA,GAAU,CAAC,OAAA,KACf,IAAIA,gBAAA,CAAY,EAAE,IAAA,EAAMC,eAAA,CAAW,iBAAA,EAAmB,OAAA,EAAS,CAAA;AAE1D,IAAM,oBAAA,GAAuB,CAClC,KAAA,EACA,KAAA,EACA,QAAA,KACW;AACX,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,MAAM,IAAA,EAAK,CAAE,WAAW,CAAA,EAAG;AAC1D,IAAA,MAAM,OAAA,CAAQ,CAAA,EAAG,KAAK,CAAA,2BAAA,CAA6B,CAAA;AAAA,EACrD;AACA,EAAA,IAAI,OAAA,CAAQ,MAAA,CAAO,KAAK,CAAA,CAAE,aAAa,QAAA,EAAU;AAC/C,IAAA,MAAM,OAAA,CAAQ,CAAA,EAAG,KAAK,CAAA,iBAAA,EAAoB,QAAQ,CAAA,MAAA,CAAQ,CAAA;AAAA,EAC5D;AACA,EAAA,OAAO,MAAM,IAAA,EAAK;AACpB,CAAA;AAEO,IAAM,cAAA,GAAiB,CAAC,KAAA,EAAgB,KAAA,GAAQ,WAAA,KAAwB;AAC7E,EAAA,MAAM,KAAA,GAAQ,oBAAA,CAAqB,KAAA,EAAO,KAAA,EAAO,GAAG,CAAA;AACpD,EAAA,IAAI,CAAC,SAAA,CAAU,IAAA,CAAK,KAAK,CAAA,EAAG;AAC1B,IAAA,MAAM,OAAA,CAAQ,CAAA,EAAG,KAAK,CAAA,oEAAA,CAAsE,CAAA;AAAA,EAC9F;AACA,EAAA,OAAO,KAAA;AACT,CAAA;AAEO,IAAM,qBAAA,GAAw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4BAA4B,CAAA;AACjC,EAAA,OAAA,CAAQ,QAAA,GAAW,CAAA;AACrB,CAAC,CAAA","file":"bin.cjs","sourcesContent":["import { ConfigError, ErrorCodes } from '@agentskit/core'\n\nconst encoder = new TextEncoder()\nconst TOOL_NAME = /^[A-Za-z0-9_.-]+$/\n\nconst invalid = (message: string): ConfigError =>\n new ConfigError({ code: ErrorCodes.AK_CONFIG_INVALID, message })\n\nexport const assertNonEmptyString = (\n input: unknown,\n field: string,\n maxBytes: number,\n): string => {\n if (typeof input !== 'string' || input.trim().length === 0) {\n throw invalid(`${field} must be a non-empty string`)\n }\n if (encoder.encode(input).byteLength > maxBytes) {\n throw invalid(`${field} must not exceed ${maxBytes} bytes`)\n }\n return input.trim()\n}\n\nexport const assertToolName = (input: unknown, field = 'tool name'): string => {\n const value = assertNonEmptyString(input, field, 128)\n if (!TOOL_NAME.test(value)) {\n throw invalid(`${field} may contain only ASCII letters, digits, underscore, hyphen, and dot`)\n }\n return value\n}\n\nexport const assertPositiveInteger = (\n input: unknown,\n field: string,\n maximum: number,\n): number => {\n if (!Number.isSafeInteger(input) || (input as number) < 1 || (input as number) > maximum) {\n throw invalid(`${field} must be a safe integer between 1 and ${maximum}`)\n }\n return input as number\n}\n\nexport const isRecord = (input: unknown): input is Record<string, unknown> => {\n if (input === null || typeof input !== 'object' || Array.isArray(input)) return false\n try {\n const prototype = Object.getPrototypeOf(input) as object | null\n return prototype === Object.prototype || prototype === null\n } catch {\n return false\n }\n}\n","import {\n ConfigError,\n ErrorCodes,\n ToolError,\n type AdapterFactory,\n type SkillDefinition,\n type ToolCall,\n type ToolDefinition,\n} from '@agentskit/core'\nimport { createRuntime, invokeStructured } from '@agentskit/runtime'\nimport { createAjvValidator } from '@agentskit/tools/validation'\nimport { assertNonEmptyString, assertPositiveInteger, assertToolName, isRecord } from './validation'\n\ntype JsonSchema = NonNullable<ToolDefinition['schema']>\n\nexport interface AgentToolConfig {\n /** Tool name exposed to the MCP host (the agent id). */\n id: string\n description: string\n /** The agent's system prompt (its skill). */\n systemPrompt: string\n /** Model adapter the agent runs on (server-side). */\n adapter: AdapterFactory\n maxSteps?: number\n /** Maximum UTF-8 bytes accepted in one task. Default 65536. */\n maxTaskBytes?: number\n}\n\nexport interface TypedAgentToolConfig extends AgentToolConfig {\n inputSchema: JsonSchema\n outputSchema: JsonSchema\n resultToolName: string\n onConfirm?: (toolCall: ToolCall) => boolean | Promise<boolean>\n}\n\n/**\n * Wrap a whole agent as a single MCP tool. The MCP host calls it with a `task`\n * string; the agent runs server-side (its own skill + reasoning loop on the\n * provided adapter) and returns the result. This is \"agents as MCP tools\" — the\n * host delegates a specialized job rather than orchestrating primitives.\n */\nexport function createAgentTool(config: AgentToolConfig): ToolDefinition {\n const id = assertToolName(config?.id, 'agent tool id')\n const description = assertNonEmptyString(config?.description, 'agent tool description', 4096)\n const systemPrompt = assertNonEmptyString(config?.systemPrompt, 'agent tool systemPrompt', 65_536)\n if (!isRecord(config?.adapter) || typeof config.adapter.createSource !== 'function') {\n throw new ConfigError({\n code: ErrorCodes.AK_CONFIG_INVALID,\n message: 'agent tool adapter must implement createSource',\n })\n }\n const maxSteps = assertPositiveInteger(config.maxSteps ?? 8, 'agent tool maxSteps', 100)\n const maxTaskBytes = assertPositiveInteger(config.maxTaskBytes ?? 65_536, 'agent tool maxTaskBytes', 1_048_576)\n const skill: SkillDefinition = {\n name: id,\n description,\n systemPrompt,\n }\n const tool: ToolDefinition = {\n name: id,\n description,\n schema: {\n type: 'object',\n properties: { task: { type: 'string', description: 'The task or input for the agent.' } },\n required: ['task'],\n additionalProperties: false,\n },\n execute: async (args: Record<string, unknown>) => {\n if (typeof args.task !== 'string' || args.task.trim().length === 0) {\n throw new ToolError({\n code: ErrorCodes.AK_TOOL_INVALID_INPUT,\n message: 'agent tool task must be a non-empty string',\n })\n }\n if (new TextEncoder().encode(args.task).byteLength > maxTaskBytes) {\n throw new ToolError({\n code: ErrorCodes.AK_TOOL_INVALID_INPUT,\n message: `agent tool task must not exceed ${maxTaskBytes} bytes`,\n })\n }\n const runtime = createRuntime({ adapter: config.adapter, maxSteps })\n const result = await runtime.run(args.task, { skill })\n return { content: result.content, steps: result.steps }\n },\n }\n return Object.freeze(tool)\n}\n\n/**\n * Expose a Registry agent without discarding its structured output contract.\n * The result tool stays internal to the runtime; only the typed outer tool is\n * visible to the MCP host.\n */\nexport function createTypedAgentTool(config: TypedAgentToolConfig): ToolDefinition {\n const id = assertToolName(config?.id, 'typed agent tool id')\n const description = assertNonEmptyString(config?.description, 'typed agent tool description', 4096)\n const systemPrompt = assertNonEmptyString(config?.systemPrompt, 'typed agent tool systemPrompt', 65_536)\n const resultToolName = assertToolName(config?.resultToolName, 'typed agent result tool name')\n const maxTaskBytes = assertPositiveInteger(config.maxTaskBytes ?? 65_536, 'typed agent input', 1_048_576)\n if (!isRecord(config?.adapter) || typeof config.adapter.createSource !== 'function') {\n throw new ConfigError({\n code: ErrorCodes.AK_CONFIG_INVALID,\n message: 'typed agent tool adapter must implement createSource',\n })\n }\n if (!isRecord(config.inputSchema) || !isRecord(config.outputSchema)) {\n throw new ConfigError({\n code: ErrorCodes.AK_CONFIG_INVALID,\n message: 'typed agent tool schemas must be JSON Schema objects',\n })\n }\n\n const validate = createAjvValidator({ rejectAdditionalProperties: true })\n try {\n validate(config.inputSchema, {})\n validate(config.outputSchema, {})\n } catch {\n throw new ConfigError({\n code: ErrorCodes.AK_CONFIG_INVALID,\n message: 'typed agent tool schemas must be valid JSON Schema',\n })\n }\n\n const submit: ToolDefinition = {\n name: resultToolName,\n description: 'Return the structured agent result.',\n schema: config.outputSchema,\n execute: async () => 'recorded',\n }\n const skill: SkillDefinition = { name: id, description, systemPrompt }\n const tool: ToolDefinition = {\n name: id,\n description,\n schema: config.inputSchema,\n execute: async (args: Record<string, unknown>) => {\n const task = JSON.stringify(args)\n if (new TextEncoder().encode(task).byteLength > maxTaskBytes) {\n throw new ToolError({\n code: ErrorCodes.AK_TOOL_INVALID_INPUT,\n message: `typed agent input must not exceed ${maxTaskBytes} bytes`,\n })\n }\n const input = validate(config.inputSchema, args)\n if (!input.valid) {\n throw new ToolError({\n code: ErrorCodes.AK_TOOL_INVALID_INPUT,\n message: input.message ?? 'typed agent input does not match its schema',\n })\n }\n return invokeStructured({\n adapter: config.adapter,\n tool: submit,\n task: `INPUT:\\n${task}`,\n parse: (value) => {\n const output = validate(config.outputSchema, value)\n if (!output.valid) {\n throw new ToolError({\n code: ErrorCodes.AK_TOOL_INVALID_INPUT,\n message: output.message ?? 'typed agent output does not match its schema',\n })\n }\n return value\n },\n skill,\n onConfirm: config.onConfirm,\n maxSteps: config.maxSteps ?? 4,\n })\n },\n }\n return Object.freeze(tool)\n}\n","import type { ToolDefinition } from '@agentskit/core'\n\nconst HOSTED = 'https://registry.agentskit.io/r'\nconst RAW = 'https://raw.githubusercontent.com/AgentsKit-io/agentskit-registry/main'\nconst REGISTRY_ID = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/\nconst TOOL_NAME = /^[A-Za-z0-9_.-]{1,128}$/\n\ntype JsonSchema = NonNullable<ToolDefinition['schema']>\n\nexport interface FetchedAgentSkill {\n id: string\n description: string\n systemPrompt: string\n}\n\nexport interface FetchedTypedAgent extends FetchedAgentSkill {\n mode: 'typed'\n inputSchema: JsonSchema\n outputSchema: JsonSchema\n resultToolName: string\n}\n\nexport type FetchedAgent = FetchedAgentSkill | FetchedTypedAgent\n\nexport interface FetchAgentSkillOptions {\n /** Per-request timeout. Default 10000 ms. */\n timeoutMs?: number\n /** Maximum UTF-8 response bytes. Default 131072. */\n maxResponseBytes?: number\n signal?: AbortSignal\n}\n\nconst isRecord = (input: unknown): input is Record<string, unknown> =>\n input !== null && typeof input === 'object' && !Array.isArray(input)\n\nconst readTypedMcpProjection = (input: Record<string, unknown>): Omit<FetchedTypedAgent, 'id' | 'description' | 'systemPrompt'> | null | undefined => {\n const projections = input.projections\n if (!isRecord(projections)) return undefined\n const mcp = projections.mcp\n if (!isRecord(mcp) || mcp.mode === undefined) return undefined\n if (mcp.mode !== 'typed') return undefined\n if (!isRecord(mcp.inputSchema) || !isRecord(mcp.outputSchema)) return null\n if (typeof mcp.resultToolName !== 'string' || !TOOL_NAME.test(mcp.resultToolName)) return null\n return {\n inputSchema: mcp.inputSchema as JsonSchema,\n mode: 'typed',\n outputSchema: mcp.outputSchema as JsonSchema,\n resultToolName: mcp.resultToolName,\n }\n}\n\nconst boundedString = (input: unknown, maximum: number): string | null => {\n if (typeof input !== 'string' || input.trim().length === 0) return null\n return new TextEncoder().encode(input).byteLength <= maximum ? input.trim() : null\n}\n\nconst readBounded = async (response: Response, maximum: number): Promise<string | null> => {\n const declared = Number(response.headers.get('content-length'))\n if (Number.isFinite(declared) && declared > maximum) return null\n if (!response.body) return ''\n\n const reader = response.body.getReader()\n const decoder = new TextDecoder()\n let bytes = 0\n let text = ''\n while (true) {\n const chunk = await reader.read()\n if (chunk.done) break\n bytes += chunk.value.byteLength\n if (bytes > maximum) {\n await reader.cancel().catch(() => undefined)\n return null\n }\n text += decoder.decode(chunk.value, { stream: true })\n }\n return text + decoder.decode()\n}\n\nconst requestText = async (\n url: string,\n fetchImpl: typeof fetch,\n options: Required<Pick<FetchAgentSkillOptions, 'maxResponseBytes' | 'timeoutMs'>> &\n Pick<FetchAgentSkillOptions, 'signal'>,\n): Promise<string | null> => {\n if (options.signal?.aborted) return null\n const controller = new AbortController()\n let resolveAbort: ((value: null) => void) | undefined\n const aborted = new Promise<null>((resolve) => {\n resolveAbort = resolve\n })\n const abort = (): void => {\n controller.abort()\n resolveAbort?.(null)\n }\n options.signal?.addEventListener('abort', abort, { once: true })\n let timer: ReturnType<typeof setTimeout> | undefined\n try {\n const request = (async (): Promise<string | null> => {\n const response = await fetchImpl(url, { signal: controller.signal })\n if (!response.ok) return null\n return readBounded(response, options.maxResponseBytes)\n })().catch(() => null)\n const timeout = new Promise<null>((resolve) => {\n timer = setTimeout(() => {\n controller.abort()\n resolve(null)\n }, options.timeoutMs)\n })\n return await Promise.race([request, timeout, aborted])\n } finally {\n if (timer !== undefined) clearTimeout(timer)\n options.signal?.removeEventListener('abort', abort)\n }\n}\n\nconst requestJson = async (\n url: string,\n fetchImpl: typeof fetch,\n options: Required<Pick<FetchAgentSkillOptions, 'maxResponseBytes' | 'timeoutMs'>> &\n Pick<FetchAgentSkillOptions, 'signal'>,\n): Promise<unknown | null> => {\n const text = await requestText(url, fetchImpl, options)\n if (text === null) return null\n try {\n return JSON.parse(text) as unknown\n } catch {\n return null\n }\n}\n\nexport async function fetchAgent(\n id: string,\n fetchImpl: typeof fetch = globalThis.fetch,\n options: FetchAgentSkillOptions = {},\n): Promise<FetchedAgent | null> {\n if (!REGISTRY_ID.test(id) || typeof fetchImpl !== 'function') return null\n const timeoutMs = options.timeoutMs ?? 10_000\n const maxResponseBytes = options.maxResponseBytes ?? 131_072\n if (\n !Number.isSafeInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 120_000 ||\n !Number.isSafeInteger(maxResponseBytes) || maxResponseBytes < 1 || maxResponseBytes > 1_048_576\n ) return null\n const bounds = { maxResponseBytes, signal: options.signal, timeoutMs }\n\n const hosted = await requestJson(`${HOSTED}/${id}.json`, fetchImpl, bounds)\n if (isRecord(hosted)) {\n const typed = readTypedMcpProjection(hosted)\n if (typed === null) return null\n if (hosted.skill === null) return null\n if (isRecord(hosted.skill)) {\n const systemPrompt = boundedString(hosted.skill.systemPrompt, 65_536)\n if (systemPrompt) {\n const description = boundedString(hosted.description, 4096) ?? id\n if (typed) return Object.freeze({ description, id, systemPrompt, ...typed })\n return Object.freeze({ description, id, systemPrompt })\n }\n }\n }\n\n const meta = await requestJson(`${RAW}/registry/${id}/meta.json`, fetchImpl, bounds)\n if (!isRecord(meta)) return null\n const typed = readTypedMcpProjection(meta)\n if (typed === null) return null\n const source = await requestText(`${RAW}/registry/${id}/agent.ts`, fetchImpl, bounds)\n if (!source) return null\n const match = source.match(/systemPrompt:\\s*`((?:\\\\.|[^`\\\\])*)`/)\n if (!match) return null\n const systemPrompt = boundedString(\n match[1].replace(/\\\\`/g, '`').replace(/\\\\\\$\\{/g, '${'),\n 65_536,\n )\n if (!systemPrompt) return null\n const skill = {\n id,\n description: boundedString(meta.description, 4096) ?? id,\n systemPrompt,\n }\n return Object.freeze(typed ? { ...skill, ...typed } : skill)\n}\n\nexport async function fetchAgentSkill(\n id: string,\n fetchImpl: typeof fetch = globalThis.fetch,\n options: FetchAgentSkillOptions = {},\n): Promise<FetchedAgentSkill | null> {\n const agent = await fetchAgent(id, fetchImpl, options)\n return agent && 'mode' in agent && agent.mode === 'typed' ? null : agent\n}\n","import { ConfigError, ErrorCodes, type ToolDefinition } from '@agentskit/core'\nimport {\n createMcpServer,\n createStdioTransport,\n type McpServer,\n type McpTransport,\n type StdioLikeProcess,\n} from '@agentskit/tools/mcp'\nimport { assertNonEmptyString, assertToolName, isRecord } from './validation'\n\nexport interface AgentsKitMcpServerOptions {\n /** AgentsKit tools to expose to the MCP host. */\n tools: ToolDefinition[]\n serverInfo?: { name: string; version: string }\n /** Observability hook (call / error / list). Logs must NOT go to stdout — it is the MCP channel. */\n onEvent?: (event: { type: 'call' | 'error' | 'list'; tool?: string; error?: string }) => void\n /**\n * Transport override. Defaults to stdio over the current process (the form\n * Codex / Claude Code / Cursor launch). Inject a custom transport for tests.\n */\n transport?: McpTransport\n}\n\n/**\n * Adapt the current Node process to the `StdioLikeProcess` the transport expects:\n * the server RECEIVES JSON-RPC on stdin and SENDS on stdout.\n */\nexport function processStdio(): StdioLikeProcess {\n return {\n stdin: { write: (chunk: string) => void process.stdout.write(chunk) },\n stdout: {\n on: (_event: 'data', cb: (chunk: Buffer | string) => void) => void process.stdin.on('data', cb),\n off: (_event: 'data', cb: (chunk: Buffer | string) => void) => void process.stdin.off('data', cb),\n },\n on: (event: 'exit' | 'close', cb: () => void) =>\n void process.on(event === 'close' ? 'beforeExit' : 'exit', cb),\n }\n}\n\n/**\n * Expose a set of AgentsKit tools as an MCP server (over stdio by default), so\n * any MCP host — Codex, Claude Code, Cursor — can call them.\n */\nexport function createAgentsKitMcpServer(options: AgentsKitMcpServerOptions): McpServer {\n if (!isRecord(options) || !Array.isArray(options.tools)) {\n throw new ConfigError({\n code: ErrorCodes.AK_CONFIG_INVALID,\n message: 'MCP server options must include a tools array',\n })\n }\n\n const names = new Set<string>()\n const tools = options.tools.map((tool, index) => {\n if (!isRecord(tool)) {\n throw new ConfigError({\n code: ErrorCodes.AK_CONFIG_INVALID,\n message: `tools[${index}] must be a tool definition`,\n })\n }\n const name = assertToolName(tool.name, `tools[${index}].name`)\n if (names.has(name)) {\n throw new ConfigError({\n code: ErrorCodes.AK_CONFIG_INVALID,\n message: `tool names must be unique; duplicate \"${name}\"`,\n })\n }\n names.add(name)\n return Object.freeze({ ...tool, name }) as ToolDefinition\n })\n\n const serverInfo = options.serverInfo === undefined\n ? { name: 'agentskit-mcp', version: '1.0.0' }\n : {\n name: assertNonEmptyString(options.serverInfo?.name, 'serverInfo.name', 128),\n version: assertNonEmptyString(options.serverInfo?.version, 'serverInfo.version', 64),\n }\n\n if (\n options.transport !== undefined &&\n (!isRecord(options.transport) ||\n typeof options.transport.send !== 'function' ||\n typeof options.transport.onMessage !== 'function')\n ) {\n throw new ConfigError({\n code: ErrorCodes.AK_CONFIG_INVALID,\n message: 'transport must implement send and onMessage',\n })\n }\n\n const onEvent = options.onEvent === undefined\n ? undefined\n : (event: Parameters<NonNullable<AgentsKitMcpServerOptions['onEvent']>>[0]): void => {\n try {\n const delivered = (options.onEvent as (value: typeof event) => unknown)(Object.freeze({ ...event }))\n if (delivered !== null && (typeof delivered === 'object' || typeof delivered === 'function')) {\n const then = (delivered as { then?: unknown }).then\n if (typeof then === 'function') void Promise.resolve(delivered).catch(() => undefined)\n }\n } catch {\n // Observation must not alter protocol behavior.\n }\n }\n\n const transport = options.transport ?? createStdioTransport(processStdio())\n return createMcpServer({\n transport,\n tools,\n serverInfo,\n onEvent,\n })\n}\n\nexport { createAgentTool, createTypedAgentTool, type AgentToolConfig, type TypedAgentToolConfig } from './agent-tool'\nexport {\n fetchAgent,\n fetchAgentSkill,\n type FetchedAgent,\n type FetchedAgentSkill,\n type FetchedTypedAgent,\n type FetchAgentSkillOptions,\n} from './registry-fetch'\nexport type { McpServer, McpTransport } from '@agentskit/tools/mcp'\n","import type { AdapterFactory, ToolDefinition } from '@agentskit/core'\nimport {\n anthropic,\n cerebras,\n cohere,\n deepseek,\n fireworks,\n gemini,\n grok,\n groq,\n huggingface,\n kimi,\n llamacpp,\n lmstudio,\n mistral,\n ollama,\n openai,\n openrouter,\n qwen,\n together,\n vllm,\n} from '@agentskit/adapters'\nimport { dispatchFromCatalog } from '@agentskit/adapters/catalog'\nimport { fetchUrl, filesystem, shell, sqliteQueryTool, webSearch } from '@agentskit/tools'\nimport type { McpServer } from '@agentskit/tools/mcp'\nimport { createAgentTool, createTypedAgentTool } from './agent-tool'\nimport { createAgentsKitMcpServer } from './index'\nimport { fetchAgent, type FetchedAgent } from './registry-fetch'\n\nconst VALUE_FLAGS = new Set([\n '--agents', '--api-key', '--base-url', '--fs-root', '--max-steps', '--model',\n '--provider', '--sqlite', '--tools',\n])\nconst BOOLEAN_FLAGS = new Set(['--allow-shell', '--help'])\nconst TOOL_IDS = new Set(['fetch', 'filesystem', 'search', 'shell', 'sqlite'])\n\nexport interface McpCliOptions {\n agents: string[]\n allowShell: boolean\n apiKey?: string\n baseUrl?: string\n fsRoot?: string\n help: boolean\n maxSteps: number\n model?: string\n provider: string\n sqlite?: string\n tools: string[]\n}\n\nexport type McpCliParseResult =\n | { message: string; status: 'rejected' }\n | { options: McpCliOptions; status: 'parsed' }\n\nconst csv = (input: string): string[] =>\n [...new Set(input.split(',').map((value) => value.trim()).filter(Boolean))]\n\nexport const parseMcpCliArgs = (argv: readonly string[]): McpCliParseResult => {\n const values = new Map<string, string>()\n const booleans = new Set<string>()\n for (let index = 0; index < argv.length; index += 1) {\n const argument = argv[index]!\n if (BOOLEAN_FLAGS.has(argument)) {\n if (booleans.has(argument)) return { message: `duplicate flag: ${argument}`, status: 'rejected' }\n booleans.add(argument)\n continue\n }\n if (!VALUE_FLAGS.has(argument)) return { message: `unknown argument: ${argument}`, status: 'rejected' }\n if (values.has(argument)) return { message: `duplicate flag: ${argument}`, status: 'rejected' }\n const value = argv[index + 1]\n if (value === undefined || value.startsWith('--')) {\n return { message: `missing value for ${argument}`, status: 'rejected' }\n }\n values.set(argument, value)\n index += 1\n }\n\n const tools = values.has('--tools') ? csv(values.get('--tools')!) : ['fetch', 'search']\n const unknownTool = tools.find((tool) => !TOOL_IDS.has(tool))\n if (unknownTool) return { message: `unknown tool: ${unknownTool}`, status: 'rejected' }\n const agents = values.has('--agents') ? csv(values.get('--agents')!) : []\n const maxStepsText = values.get('--max-steps') ?? '8'\n const maxSteps = Number(maxStepsText)\n if (!Number.isSafeInteger(maxSteps) || maxSteps < 1 || maxSteps > 100) {\n return { message: '--max-steps must be a safe integer between 1 and 100', status: 'rejected' }\n }\n\n return {\n options: {\n agents,\n allowShell: booleans.has('--allow-shell'),\n apiKey: values.get('--api-key'),\n baseUrl: values.get('--base-url'),\n fsRoot: values.get('--fs-root'),\n help: booleans.has('--help'),\n maxSteps,\n model: values.get('--model'),\n provider: (values.get('--provider') ?? 'openai').toLowerCase(),\n sqlite: values.get('--sqlite'),\n tools,\n },\n status: 'parsed',\n }\n}\n\ntype KeyedFactory = (config: { apiKey: string; baseUrl?: string; model: string }) => AdapterFactory\ntype LocalFactory = (config: { baseUrl?: string; model: string }) => AdapterFactory\n\nconst KEYED: Record<string, KeyedFactory> = {\n anthropic, cerebras, cohere, deepseek, fireworks, gemini, grok, groq,\n huggingface, kimi, llamacpp, lmstudio, mistral, openai, openrouter, qwen,\n together, vllm,\n}\nconst LOCAL: Record<string, LocalFactory> = { ollama }\nconst LOCAL_COMPAT = new Set(['llamacpp', 'lmstudio', 'vllm'])\nconst DEFAULT_MODEL: Record<string, string> = {\n anthropic: 'claude-sonnet-4-6',\n deepseek: 'deepseek-chat',\n gemini: 'gemini-2.0-flash',\n grok: 'grok-2',\n groq: 'openai/gpt-oss-120b',\n mistral: 'mistral-large-latest',\n ollama: 'llama3',\n openai: 'gpt-4o',\n}\n\nexport interface McpCliDependencies {\n createServer?: typeof createAgentsKitMcpServer\n env?: Readonly<Record<string, string | undefined>>\n fetchAgent?: (id: string) => Promise<FetchedAgent | null>\n /** @deprecated Use fetchAgent; retained for dependency injection compatibility. */\n fetchSkill?: (id: string) => Promise<FetchedAgent | null>\n warn?: (message: string) => void\n}\n\nexport type McpCliRunResult =\n | { exitCode: 0; server: McpServer; status: 'started'; toolNames: string[] }\n | { exitCode: 0; status: 'help' }\n | { exitCode: 1; status: 'rejected' }\n\nexport const MCP_CLI_HELP = [\n 'Usage: agentskit-mcp [options]',\n '--tools <fetch,search,filesystem,shell,sqlite>',\n '--agents <registry-ids> --provider <provider> --model <model>',\n '--fs-root <dir> --sqlite <file> --allow-shell',\n].join('\\n')\n\nconst buildPrimitiveTools = (options: McpCliOptions, warn: (message: string) => void): ToolDefinition[] => {\n const tools: ToolDefinition[] = []\n if (options.tools.includes('fetch')) tools.push(fetchUrl())\n if (options.tools.includes('search')) tools.push(webSearch())\n if (options.tools.includes('filesystem')) {\n if (options.fsRoot) tools.push(...filesystem({ basePath: options.fsRoot }))\n else warn('skipping \"filesystem\": pass --fs-root <dir>')\n }\n if (options.tools.includes('sqlite')) {\n if (options.sqlite) tools.push(sqliteQueryTool({ path: options.sqlite }))\n else warn('skipping \"sqlite\": pass --sqlite <file>')\n }\n if (options.tools.includes('shell')) {\n if (options.allowShell) tools.push(shell())\n else warn('skipping \"shell\": pass --allow-shell (runs commands)')\n }\n return tools\n}\n\nconst resolveAdapter = (\n options: McpCliOptions,\n env: Readonly<Record<string, string | undefined>>,\n warn: (message: string) => void,\n): AdapterFactory | null => {\n const model = options.model ?? DEFAULT_MODEL[options.provider]\n if (!model) {\n warn(`--agents needs a model for \"${options.provider}\": pass --model`)\n return null\n }\n const local = LOCAL[options.provider]\n if (local) return local({ baseUrl: options.baseUrl, model })\n\n const envName = `${options.provider.toUpperCase().replace(/-/g, '_')}_API_KEY`\n const apiKey = options.apiKey ?? env[envName] ?? (LOCAL_COMPAT.has(options.provider) ? 'local' : undefined)\n if (!apiKey) {\n warn(`--agents needs a key for \"${options.provider}\": pass --api-key or set ${envName}`)\n return null\n }\n const keyed = KEYED[options.provider]\n if (keyed) return keyed({ apiKey, baseUrl: options.baseUrl, model })\n try {\n return dispatchFromCatalog({ apiKey, baseUrl: options.baseUrl, model, provider: options.provider })\n } catch {\n warn(`unknown or incompatible provider \"${options.provider}\"`)\n return null\n }\n}\n\nexport const runMcpCli = async (\n argv: readonly string[],\n dependencies: McpCliDependencies = {},\n): Promise<McpCliRunResult> => {\n const warn = dependencies.warn ?? (() => undefined)\n const parsed = parseMcpCliArgs(argv)\n if (parsed.status === 'rejected') {\n warn(parsed.message)\n return { exitCode: 1, status: 'rejected' }\n }\n if (parsed.options.help) {\n warn(MCP_CLI_HELP)\n return { exitCode: 0, status: 'help' }\n }\n\n const tools = buildPrimitiveTools(parsed.options, warn)\n if (parsed.options.agents.length > 0) {\n const adapter = resolveAdapter(parsed.options, dependencies.env ?? process.env, warn)\n if (adapter) {\n const fetch = dependencies.fetchAgent ?? dependencies.fetchSkill ?? fetchAgent\n for (const id of parsed.options.agents) {\n const agent = await fetch(id).catch(() => null)\n if (!agent) {\n warn(`skipping agent \"${id}\": not found or not runnable`)\n continue\n }\n try {\n tools.push('mode' in agent && agent.mode === 'typed'\n ? createTypedAgentTool({ ...agent, adapter, maxSteps: parsed.options.maxSteps })\n : createAgentTool({ ...agent, adapter, maxSteps: parsed.options.maxSteps }))\n } catch {\n warn(`skipping agent \"${id}\": invalid projection`)\n }\n }\n }\n }\n\n if (tools.length === 0) {\n warn('no tools or agents enabled — nothing to serve')\n return { exitCode: 1, status: 'rejected' }\n }\n const seen = new Set<string>()\n const duplicate = tools.find((tool) => {\n if (seen.has(tool.name)) return true\n seen.add(tool.name)\n return false\n })\n if (duplicate) {\n warn(`duplicate tool name: ${duplicate.name}`)\n return { exitCode: 1, status: 'rejected' }\n }\n const createServer = dependencies.createServer ?? createAgentsKitMcpServer\n let server: McpServer\n try {\n server = createServer({\n tools,\n onEvent: (event) => {\n if (event.type === 'error') warn(`tool error (${event.tool ?? 'unknown'}): ${event.error ?? 'unknown'}`)\n },\n })\n } catch {\n warn('failed to start MCP server')\n return { exitCode: 1, status: 'rejected' }\n }\n const toolNames = tools.map((tool) => tool.name)\n warn(`serving ${toolNames.length} item(s) over stdio (${toolNames.join(', ')})`)\n return { exitCode: 0, server, status: 'started', toolNames }\n}\n","#!/usr/bin/env node\nimport { runMcpCli } from './cli'\n\nconst warn = (message: string): void => {\n process.stderr.write(`agentskit-mcp: ${message}\\n`)\n}\n\nvoid runMcpCli(process.argv.slice(2), { warn }).then((result) => {\n process.exitCode = result.exitCode\n}).catch(() => {\n warn('unexpected startup failure')\n process.exitCode = 1\n})\n"]}
|
package/dist/bin.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { fetchAgent, createTypedAgentTool, createAgentTool, createAgentsKitMcpServer } from './chunk-DU5RLF44.js';
|
|
3
3
|
import { ollama, vllm, together, qwen, openrouter, openai, mistral, lmstudio, llamacpp, kimi, huggingface, groq, grok, gemini, fireworks, deepseek, cohere, cerebras, anthropic } from '@agentskit/adapters';
|
|
4
4
|
import { dispatchFromCatalog } from '@agentskit/adapters/catalog';
|
|
5
5
|
import { fetchUrl, webSearch, filesystem, sqliteQueryTool, shell } from '@agentskit/tools';
|
|
@@ -157,14 +157,18 @@ var runMcpCli = async (argv, dependencies = {}) => {
|
|
|
157
157
|
if (parsed.options.agents.length > 0) {
|
|
158
158
|
const adapter = resolveAdapter(parsed.options, dependencies.env ?? process.env, warn2);
|
|
159
159
|
if (adapter) {
|
|
160
|
-
const
|
|
160
|
+
const fetch = dependencies.fetchAgent ?? dependencies.fetchSkill ?? fetchAgent;
|
|
161
161
|
for (const id of parsed.options.agents) {
|
|
162
|
-
const
|
|
163
|
-
if (!
|
|
162
|
+
const agent = await fetch(id).catch(() => null);
|
|
163
|
+
if (!agent) {
|
|
164
164
|
warn2(`skipping agent "${id}": not found or not runnable`);
|
|
165
165
|
continue;
|
|
166
166
|
}
|
|
167
|
-
|
|
167
|
+
try {
|
|
168
|
+
tools.push("mode" in agent && agent.mode === "typed" ? createTypedAgentTool({ ...agent, adapter, maxSteps: parsed.options.maxSteps }) : createAgentTool({ ...agent, adapter, maxSteps: parsed.options.maxSteps }));
|
|
169
|
+
} catch {
|
|
170
|
+
warn2(`skipping agent "${id}": invalid projection`);
|
|
171
|
+
}
|
|
168
172
|
}
|
|
169
173
|
}
|
|
170
174
|
}
|