@agentskit/mcp 0.2.17 → 0.2.20
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 +56 -2
- package/dist/bin.cjs +386 -120
- package/dist/bin.cjs.map +1 -1
- package/dist/bin.js +176 -85
- package/dist/bin.js.map +1 -1
- package/dist/chunk-CKAUENP5.js +258 -0
- package/dist/chunk-CKAUENP5.js.map +1 -0
- package/dist/index.cjs +207 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -7
- package/dist/index.d.ts +11 -7
- package/dist/index.js +1 -1
- package/package.json +12 -8
- package/dist/chunk-F5SVUT7Z.js +0 -85
- package/dist/chunk-F5SVUT7Z.js.map +0 -1
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/agent-tool.ts","../src/registry-fetch.ts","../src/index.ts"],"names":["runtime","createRuntime","createStdioTransport","createMcpServer"],"mappings":";;;;;;AAoBO,SAAS,gBAAgB,MAAA,EAAyC;AACvE,EAAA,MAAM,KAAA,GAAyB;AAAA,IAC7B,MAAM,MAAA,CAAO,EAAA;AAAA,IACb,aAAa,MAAA,CAAO,WAAA;AAAA,IACpB,cAAc,MAAA,CAAO;AAAA,GACvB;AACA,EAAA,OAAO;AAAA,IACL,MAAM,MAAA,CAAO,EAAA;AAAA,IACb,aAAa,MAAA,CAAO,WAAA;AAAA,IACpB,MAAA,EAAQ;AAAA,MACN,IAAA,EAAM,QAAA;AAAA,MACN,UAAA,EAAY,EAAE,IAAA,EAAM,EAAE,MAAM,QAAA,EAAU,WAAA,EAAa,oCAAmC,EAAE;AAAA,MACxF,QAAA,EAAU,CAAC,MAAM;AAAA,KACnB;AAAA,IACA,OAAA,EAAS,OAAO,IAAA,KAAkC;AAChD,MAAA,MAAMA,SAAA,GAAUC,qBAAA,CAAc,EAAE,OAAA,EAAS,MAAA,CAAO,SAAS,QAAA,EAAU,MAAA,CAAO,QAA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OAAA,EAA+C;AACtF,EAAA,MAAM,SAAA,GAAY,OAAA,CAAQ,SAAA,IAAaE,wBAAA,CAAqB,cAAc,CAAA;AAC1E,EAAA,OAAOC,mBAAA,CAAgB;AAAA,IACrB,SAAA;AAAA,IACA,OAAO,OAAA,CAAQ,KAAA;AAAA,IACf,YAAY,OAAA,CAAQ,UAAA,IAAc,EAAE,IAAA,EAAM,eAAA,EAAiB,SAAS,OAAA,EAAQ;AAAA,IAC5E,SAAS,OAAA,CAAQ;AAAA,GAClB,CAAA;AACH","file":"index.cjs","sourcesContent":["import type { AdapterFactory, SkillDefinition, ToolDefinition } from '@agentskit/core'\nimport { createRuntime } from '@agentskit/runtime'\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}\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 skill: SkillDefinition = {\n name: config.id,\n description: config.description,\n systemPrompt: config.systemPrompt,\n }\n return {\n name: config.id,\n description: config.description,\n schema: {\n type: 'object',\n properties: { task: { type: 'string', description: 'The task or input for the agent.' } },\n required: ['task'],\n },\n execute: async (args: Record<string, unknown>) => {\n const runtime = createRuntime({ adapter: config.adapter, maxSteps: config.maxSteps ?? 8 })\n const result = await runtime.run(String(args.task ?? ''), { skill })\n return { content: result.content, steps: result.steps }\n },\n }\n}\n","const HOSTED = 'https://registry.agentskit.io/r'\nconst RAW = 'https://raw.githubusercontent.com/AgentsKit-io/agentskit-registry/main'\n\nexport interface FetchedAgentSkill {\n id: string\n description: string\n systemPrompt: string\n}\n\n/**\n * Fetch a registry agent's runnable skill (id, description, systemPrompt) so it\n * can be exposed as an MCP tool. Hosted index first, raw-GitHub fallback. Returns\n * null for tool-composing agents (no inline prompt) or unknown ids.\n */\nexport async function fetchAgentSkill(\n id: string,\n fetchImpl: typeof fetch = globalThis.fetch,\n): Promise<FetchedAgentSkill | null> {\n const tryUrl = async (url: string): Promise<unknown | null> => {\n try {\n const res = await fetchImpl(url)\n return res.ok ? await res.json() : null\n } catch {\n return null\n }\n }\n\n const hosted = (await tryUrl(`${HOSTED}/${id}.json`)) as\n | { description?: string; skill?: { systemPrompt?: string } | null }\n | null\n if (hosted?.skill?.systemPrompt) {\n return { id, description: hosted.description ?? id, systemPrompt: hosted.skill.systemPrompt }\n }\n\n // Fallback: extract the inline skill from the raw agent.ts source.\n const meta = (await tryUrl(`${RAW}/registry/${id}/meta.json`)) as { description?: string } | null\n if (!meta) return null\n let src: string | null = null\n try {\n const res = await fetchImpl(`${RAW}/registry/${id}/agent.ts`)\n src = res.ok ? await res.text() : null\n } catch {\n src = null\n }\n if (!src) return null\n const m = src.match(/systemPrompt:\\s*`((?:\\\\.|[^`\\\\])*)`/)\n if (!m) return null\n return {\n id,\n description: meta.description ?? id,\n systemPrompt: m[1].replace(/\\\\`/g, '`').replace(/\\\\\\$\\{/g, '${'),\n }\n}\n","import type { ToolDefinition } from '@agentskit/core'\nimport {\n createMcpServer,\n createStdioTransport,\n type McpServer,\n type McpTransport,\n type StdioLikeProcess,\n} from '@agentskit/tools/mcp'\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 * Claude Desktop / Cursor / Windsurf 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 — Claude Desktop, Cursor, Windsurf — can call them.\n */\nexport function createAgentsKitMcpServer(options: AgentsKitMcpServerOptions): McpServer {\n const transport = options.transport ?? createStdioTransport(processStdio())\n return createMcpServer({\n transport,\n tools: options.tools,\n serverInfo: options.serverInfo ?? { name: 'agentskit-mcp', version: '0.1.0' },\n onEvent: options.onEvent,\n })\n}\n\nexport { createAgentTool, type AgentToolConfig } from './agent-tool'\nexport { fetchAgentSkill, type FetchedAgentSkill } from './registry-fetch'\nexport type { McpServer, McpTransport } from '@agentskit/tools/mcp'\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/validation.ts","../src/agent-tool.ts","../src/registry-fetch.ts","../src/index.ts"],"names":["ConfigError","ErrorCodes","ToolError","runtime","createRuntime","isRecord","systemPrompt","createStdioTransport","createMcpServer"],"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,I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,EAAS;AAAA,KACV,CAAA;AAAA,EACH;AAEA,EAAA,MAAM,UAAU,OAAA,CAAQ,OAAA,KAAY,MAAA,GAChC,MAAA,GACA,CAAC,KAAA,KAAkF;AACjF,IAAA,IAAI;AACF,MAAA,MAAM,SAAA,GAAa,QAAQ,OAAA,CAA6C,MAAA,CAAO,OAAO,EAAE,GAAG,KAAA,EAAO,CAAC,CAAA;AACnG,MAAA,IAAI,cAAc,IAAA,KAAS,OAAO,cAAc,QAAA,IAAY,OAAO,cAAc,UAAA,CAAA,EAAa;AAC5F,QAAA,MAAM,OAAQ,SAAA,CAAiC,IAAA;AAC/C,QAAA,IAAI,OAAO,IAAA,KAAS,UAAA,EAAY,KAAK,OAAA,CAAQ,QAAQ,SAAS,CAAA,CAAE,KAAA,CAAM,MAAM,KAAA,CAAS,CAAA;AAAA,MACvF;AAAA,IACF,CAAA,CAAA,MAAQ;AAAA,IAER;AAAA,EACF,CAAA;AAEJ,EAAA,MAAM,SAAA,GAAY,OAAA,CAAQ,SAAA,IAAaM,wBAAA,CAAqB,cAAc,CAAA;AAC1E,EAAA,OAAOC,mBAAA,CAAgB;AAAA,IACrB,SAAA;AAAA,IACA,KAAA;AAAA,IACA,UAAA;AAAA,IACA;AAAA,GACD,CAAA;AACH","file":"index.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 * Claude Desktop / Cursor / Windsurf 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 — Claude Desktop, Cursor, Windsurf — 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"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -11,6 +11,8 @@ interface AgentToolConfig {
|
|
|
11
11
|
/** Model adapter the agent runs on (server-side). */
|
|
12
12
|
adapter: AdapterFactory;
|
|
13
13
|
maxSteps?: number;
|
|
14
|
+
/** Maximum UTF-8 bytes accepted in one task. Default 65536. */
|
|
15
|
+
maxTaskBytes?: number;
|
|
14
16
|
}
|
|
15
17
|
/**
|
|
16
18
|
* Wrap a whole agent as a single MCP tool. The MCP host calls it with a `task`
|
|
@@ -25,12 +27,14 @@ interface FetchedAgentSkill {
|
|
|
25
27
|
description: string;
|
|
26
28
|
systemPrompt: string;
|
|
27
29
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
interface FetchAgentSkillOptions {
|
|
31
|
+
/** Per-request timeout. Default 10000 ms. */
|
|
32
|
+
timeoutMs?: number;
|
|
33
|
+
/** Maximum UTF-8 response bytes. Default 131072. */
|
|
34
|
+
maxResponseBytes?: number;
|
|
35
|
+
signal?: AbortSignal;
|
|
36
|
+
}
|
|
37
|
+
declare function fetchAgentSkill(id: string, fetchImpl?: typeof fetch, options?: FetchAgentSkillOptions): Promise<FetchedAgentSkill | null>;
|
|
34
38
|
|
|
35
39
|
interface AgentsKitMcpServerOptions {
|
|
36
40
|
/** AgentsKit tools to expose to the MCP host. */
|
|
@@ -62,4 +66,4 @@ declare function processStdio(): StdioLikeProcess;
|
|
|
62
66
|
*/
|
|
63
67
|
declare function createAgentsKitMcpServer(options: AgentsKitMcpServerOptions): McpServer;
|
|
64
68
|
|
|
65
|
-
export { type AgentToolConfig, type AgentsKitMcpServerOptions, type FetchedAgentSkill, createAgentTool, createAgentsKitMcpServer, fetchAgentSkill, processStdio };
|
|
69
|
+
export { type AgentToolConfig, type AgentsKitMcpServerOptions, type FetchAgentSkillOptions, type FetchedAgentSkill, createAgentTool, createAgentsKitMcpServer, fetchAgentSkill, processStdio };
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ interface AgentToolConfig {
|
|
|
11
11
|
/** Model adapter the agent runs on (server-side). */
|
|
12
12
|
adapter: AdapterFactory;
|
|
13
13
|
maxSteps?: number;
|
|
14
|
+
/** Maximum UTF-8 bytes accepted in one task. Default 65536. */
|
|
15
|
+
maxTaskBytes?: number;
|
|
14
16
|
}
|
|
15
17
|
/**
|
|
16
18
|
* Wrap a whole agent as a single MCP tool. The MCP host calls it with a `task`
|
|
@@ -25,12 +27,14 @@ interface FetchedAgentSkill {
|
|
|
25
27
|
description: string;
|
|
26
28
|
systemPrompt: string;
|
|
27
29
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
interface FetchAgentSkillOptions {
|
|
31
|
+
/** Per-request timeout. Default 10000 ms. */
|
|
32
|
+
timeoutMs?: number;
|
|
33
|
+
/** Maximum UTF-8 response bytes. Default 131072. */
|
|
34
|
+
maxResponseBytes?: number;
|
|
35
|
+
signal?: AbortSignal;
|
|
36
|
+
}
|
|
37
|
+
declare function fetchAgentSkill(id: string, fetchImpl?: typeof fetch, options?: FetchAgentSkillOptions): Promise<FetchedAgentSkill | null>;
|
|
34
38
|
|
|
35
39
|
interface AgentsKitMcpServerOptions {
|
|
36
40
|
/** AgentsKit tools to expose to the MCP host. */
|
|
@@ -62,4 +66,4 @@ declare function processStdio(): StdioLikeProcess;
|
|
|
62
66
|
*/
|
|
63
67
|
declare function createAgentsKitMcpServer(options: AgentsKitMcpServerOptions): McpServer;
|
|
64
68
|
|
|
65
|
-
export { type AgentToolConfig, type AgentsKitMcpServerOptions, type FetchedAgentSkill, createAgentTool, createAgentsKitMcpServer, fetchAgentSkill, processStdio };
|
|
69
|
+
export { type AgentToolConfig, type AgentsKitMcpServerOptions, type FetchAgentSkillOptions, type FetchedAgentSkill, createAgentTool, createAgentsKitMcpServer, fetchAgentSkill, processStdio };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { createAgentTool, createAgentsKitMcpServer, fetchAgentSkill, processStdio } from './chunk-
|
|
1
|
+
export { createAgentTool, createAgentsKitMcpServer, fetchAgentSkill, processStdio } from './chunk-CKAUENP5.js';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentskit/mcp",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.20",
|
|
4
4
|
"description": "Expose AgentsKit tools as an MCP server — use them from Claude Desktop, Cursor, Windsurf, or any MCP host.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agentskit",
|
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
"cursor"
|
|
14
14
|
],
|
|
15
15
|
"type": "module",
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=20"
|
|
18
|
+
},
|
|
16
19
|
"sideEffects": false,
|
|
17
20
|
"main": "./dist/index.cjs",
|
|
18
21
|
"module": "./dist/index.js",
|
|
@@ -31,10 +34,10 @@
|
|
|
31
34
|
"dist"
|
|
32
35
|
],
|
|
33
36
|
"dependencies": {
|
|
34
|
-
"@agentskit/adapters": "0.13.
|
|
35
|
-
"@agentskit/core": "1.12.
|
|
36
|
-
"@agentskit/runtime": "0.10.
|
|
37
|
-
"@agentskit/tools": "0.
|
|
37
|
+
"@agentskit/adapters": "0.13.16",
|
|
38
|
+
"@agentskit/core": "1.12.4",
|
|
39
|
+
"@agentskit/runtime": "0.10.11",
|
|
40
|
+
"@agentskit/tools": "0.12.1"
|
|
38
41
|
},
|
|
39
42
|
"devDependencies": {
|
|
40
43
|
"@types/node": "^25.9.5",
|
|
@@ -43,7 +46,8 @@
|
|
|
43
46
|
"vitest": "^4.1.10"
|
|
44
47
|
},
|
|
45
48
|
"publishConfig": {
|
|
46
|
-
"access": "public"
|
|
49
|
+
"access": "public",
|
|
50
|
+
"provenance": true
|
|
47
51
|
},
|
|
48
52
|
"license": "MIT",
|
|
49
53
|
"homepage": "https://www.agentskit.io/docs/packages/mcp",
|
|
@@ -54,8 +58,8 @@
|
|
|
54
58
|
},
|
|
55
59
|
"author": "AgentsKit Contributors",
|
|
56
60
|
"agentskit": {
|
|
57
|
-
"stability": "
|
|
58
|
-
"stabilityNote": "
|
|
61
|
+
"stability": "beta",
|
|
62
|
+
"stabilityNote": "Tool bridge, CLI, agent delegation, registry IO, and publication boundaries hardened (ADR-0028)."
|
|
59
63
|
},
|
|
60
64
|
"scripts": {
|
|
61
65
|
"build": "tsup",
|
package/dist/chunk-F5SVUT7Z.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { createStdioTransport, createMcpServer } from '@agentskit/tools/mcp';
|
|
2
|
-
import { createRuntime } from '@agentskit/runtime';
|
|
3
|
-
|
|
4
|
-
// src/index.ts
|
|
5
|
-
function createAgentTool(config) {
|
|
6
|
-
const skill = {
|
|
7
|
-
name: config.id,
|
|
8
|
-
description: config.description,
|
|
9
|
-
systemPrompt: config.systemPrompt
|
|
10
|
-
};
|
|
11
|
-
return {
|
|
12
|
-
name: config.id,
|
|
13
|
-
description: config.description,
|
|
14
|
-
schema: {
|
|
15
|
-
type: "object",
|
|
16
|
-
properties: { task: { type: "string", description: "The task or input for the agent." } },
|
|
17
|
-
required: ["task"]
|
|
18
|
-
},
|
|
19
|
-
execute: async (args) => {
|
|
20
|
-
const runtime = createRuntime({ adapter: config.adapter, maxSteps: config.maxSteps ?? 8 });
|
|
21
|
-
const result = await runtime.run(String(args.task ?? ""), { skill });
|
|
22
|
-
return { content: result.content, steps: result.steps };
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// src/registry-fetch.ts
|
|
28
|
-
var HOSTED = "https://registry.agentskit.io/r";
|
|
29
|
-
var RAW = "https://raw.githubusercontent.com/AgentsKit-io/agentskit-registry/main";
|
|
30
|
-
async function fetchAgentSkill(id, fetchImpl = globalThis.fetch) {
|
|
31
|
-
const tryUrl = async (url) => {
|
|
32
|
-
try {
|
|
33
|
-
const res = await fetchImpl(url);
|
|
34
|
-
return res.ok ? await res.json() : null;
|
|
35
|
-
} catch {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
const hosted = await tryUrl(`${HOSTED}/${id}.json`);
|
|
40
|
-
if (hosted?.skill?.systemPrompt) {
|
|
41
|
-
return { id, description: hosted.description ?? id, systemPrompt: hosted.skill.systemPrompt };
|
|
42
|
-
}
|
|
43
|
-
const meta = await tryUrl(`${RAW}/registry/${id}/meta.json`);
|
|
44
|
-
if (!meta) return null;
|
|
45
|
-
let src = null;
|
|
46
|
-
try {
|
|
47
|
-
const res = await fetchImpl(`${RAW}/registry/${id}/agent.ts`);
|
|
48
|
-
src = res.ok ? await res.text() : null;
|
|
49
|
-
} catch {
|
|
50
|
-
src = null;
|
|
51
|
-
}
|
|
52
|
-
if (!src) return null;
|
|
53
|
-
const m = src.match(/systemPrompt:\s*`((?:\\.|[^`\\])*)`/);
|
|
54
|
-
if (!m) return null;
|
|
55
|
-
return {
|
|
56
|
-
id,
|
|
57
|
-
description: meta.description ?? id,
|
|
58
|
-
systemPrompt: m[1].replace(/\\`/g, "`").replace(/\\\$\{/g, "${")
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// src/index.ts
|
|
63
|
-
function processStdio() {
|
|
64
|
-
return {
|
|
65
|
-
stdin: { write: (chunk) => void process.stdout.write(chunk) },
|
|
66
|
-
stdout: {
|
|
67
|
-
on: (_event, cb) => void process.stdin.on("data", cb),
|
|
68
|
-
off: (_event, cb) => void process.stdin.off("data", cb)
|
|
69
|
-
},
|
|
70
|
-
on: (event, cb) => void process.on(event === "close" ? "beforeExit" : "exit", cb)
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
function createAgentsKitMcpServer(options) {
|
|
74
|
-
const transport = options.transport ?? createStdioTransport(processStdio());
|
|
75
|
-
return createMcpServer({
|
|
76
|
-
transport,
|
|
77
|
-
tools: options.tools,
|
|
78
|
-
serverInfo: options.serverInfo ?? { name: "agentskit-mcp", version: "0.1.0" },
|
|
79
|
-
onEvent: options.onEvent
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export { createAgentTool, createAgentsKitMcpServer, fetchAgentSkill, processStdio };
|
|
84
|
-
//# sourceMappingURL=chunk-F5SVUT7Z.js.map
|
|
85
|
-
//# sourceMappingURL=chunk-F5SVUT7Z.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/agent-tool.ts","../src/registry-fetch.ts","../src/index.ts"],"names":[],"mappings":";;;;AAoBO,SAAS,gBAAgB,MAAA,EAAyC;AACvE,EAAA,MAAM,KAAA,GAAyB;AAAA,IAC7B,MAAM,MAAA,CAAO,EAAA;AAAA,IACb,aAAa,MAAA,CAAO,WAAA;AA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EAAE;AAAA,IACpE,MAAA,EAAQ;AAAA,MACN,EAAA,EAAI,CAAC,MAAA,EAAgB,EAAA,KAAyC,KAAK,OAAA,CAAQ,KAAA,CAAM,EAAA,CAAG,MAAA,EAAQ,EAAE,CAAA;AAAA,MAC9F,GAAA,EAAK,CAAC,MAAA,EAAgB,EAAA,KAAyC,KAAK,OAAA,CAAQ,KAAA,CAAM,GAAA,CAAI,MAAA,EAAQ,EAAE;AAAA,KAClG;AAAA,IACA,EAAA,EAAI,CAAC,KAAA,EAAyB,EAAA,KAC5B,KAAK,OAAA,CAAQ,EAAA,CAAG,KAAA,KAAU,OAAA,GAAU,YAAA,GAAe,MAAA,EAAQ,EAAE;AAAA,GACjE;AACF;AAMO,SAAS,yBAAyB,OAAA,EAA+C;AACtF,EAAA,MAAM,SAAA,GAAY,OAAA,CAAQ,SAAA,IAAa,oBAAA,CAAqB,cAAc,CAAA;AAC1E,EAAA,OAAO,eAAA,CAAgB;AAAA,IACrB,SAAA;AAAA,IACA,OAAO,OAAA,CAAQ,KAAA;AAAA,IACf,YAAY,OAAA,CAAQ,UAAA,IAAc,EAAE,IAAA,EAAM,eAAA,EAAiB,SAAS,OAAA,EAAQ;AAAA,IAC5E,SAAS,OAAA,CAAQ;AAAA,GAClB,CAAA;AACH","file":"chunk-F5SVUT7Z.js","sourcesContent":["import type { AdapterFactory, SkillDefinition, ToolDefinition } from '@agentskit/core'\nimport { createRuntime } from '@agentskit/runtime'\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}\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 skill: SkillDefinition = {\n name: config.id,\n description: config.description,\n systemPrompt: config.systemPrompt,\n }\n return {\n name: config.id,\n description: config.description,\n schema: {\n type: 'object',\n properties: { task: { type: 'string', description: 'The task or input for the agent.' } },\n required: ['task'],\n },\n execute: async (args: Record<string, unknown>) => {\n const runtime = createRuntime({ adapter: config.adapter, maxSteps: config.maxSteps ?? 8 })\n const result = await runtime.run(String(args.task ?? ''), { skill })\n return { content: result.content, steps: result.steps }\n },\n }\n}\n","const HOSTED = 'https://registry.agentskit.io/r'\nconst RAW = 'https://raw.githubusercontent.com/AgentsKit-io/agentskit-registry/main'\n\nexport interface FetchedAgentSkill {\n id: string\n description: string\n systemPrompt: string\n}\n\n/**\n * Fetch a registry agent's runnable skill (id, description, systemPrompt) so it\n * can be exposed as an MCP tool. Hosted index first, raw-GitHub fallback. Returns\n * null for tool-composing agents (no inline prompt) or unknown ids.\n */\nexport async function fetchAgentSkill(\n id: string,\n fetchImpl: typeof fetch = globalThis.fetch,\n): Promise<FetchedAgentSkill | null> {\n const tryUrl = async (url: string): Promise<unknown | null> => {\n try {\n const res = await fetchImpl(url)\n return res.ok ? await res.json() : null\n } catch {\n return null\n }\n }\n\n const hosted = (await tryUrl(`${HOSTED}/${id}.json`)) as\n | { description?: string; skill?: { systemPrompt?: string } | null }\n | null\n if (hosted?.skill?.systemPrompt) {\n return { id, description: hosted.description ?? id, systemPrompt: hosted.skill.systemPrompt }\n }\n\n // Fallback: extract the inline skill from the raw agent.ts source.\n const meta = (await tryUrl(`${RAW}/registry/${id}/meta.json`)) as { description?: string } | null\n if (!meta) return null\n let src: string | null = null\n try {\n const res = await fetchImpl(`${RAW}/registry/${id}/agent.ts`)\n src = res.ok ? await res.text() : null\n } catch {\n src = null\n }\n if (!src) return null\n const m = src.match(/systemPrompt:\\s*`((?:\\\\.|[^`\\\\])*)`/)\n if (!m) return null\n return {\n id,\n description: meta.description ?? id,\n systemPrompt: m[1].replace(/\\\\`/g, '`').replace(/\\\\\\$\\{/g, '${'),\n }\n}\n","import type { ToolDefinition } from '@agentskit/core'\nimport {\n createMcpServer,\n createStdioTransport,\n type McpServer,\n type McpTransport,\n type StdioLikeProcess,\n} from '@agentskit/tools/mcp'\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 * Claude Desktop / Cursor / Windsurf 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 — Claude Desktop, Cursor, Windsurf — can call them.\n */\nexport function createAgentsKitMcpServer(options: AgentsKitMcpServerOptions): McpServer {\n const transport = options.transport ?? createStdioTransport(processStdio())\n return createMcpServer({\n transport,\n tools: options.tools,\n serverInfo: options.serverInfo ?? { name: 'agentskit-mcp', version: '0.1.0' },\n onEvent: options.onEvent,\n })\n}\n\nexport { createAgentTool, type AgentToolConfig } from './agent-tool'\nexport { fetchAgentSkill, type FetchedAgentSkill } from './registry-fetch'\nexport type { McpServer, McpTransport } from '@agentskit/tools/mcp'\n"]}
|