diff --git a/.project/plans/agent/20261124-0950-the-mcp-client-reads-a-servers-skills/implemented.md b/.project/plans/agent/20261124-0950-the-mcp-client-reads-a-servers-skills/implemented.md new file mode 100644 index 0000000..a16b4c1 --- /dev/null +++ b/.project/plans/agent/20261124-0950-the-mcp-client-reads-a-servers-skills/implemented.md @@ -0,0 +1,18 @@ +--- +title: The MCP client reads a server's skills - implemented +date: 2026-11-24 +refs: + - "[code://packages/mcp-client/src/connect.ts](../../../../packages/mcp-client/src/connect.ts) - `servesSkills`, `skills`, `skill`, `read`" + - "[code://packages/mcp-client/src/types.ts](../../../../packages/mcp-client/src/types.ts) - `McpSkillInfo`, `McpSkillResource`, `McpResourceContents`" +--- + +A connection keeps the server's `capabilities`, says `servesSkills`, lists every page of `skills/list`, gets one skill with `skills/get`, and reads a file with `resources/read`. + +## Verified + +- `connect.test.ts`: two cases against `test-fixtures/skills-server.mjs`. +- `pnpm test`: 93 files, 1202 cases, no type errors. `pnpm typecheck` passes. + +## Departures from the plan + +- None. diff --git a/.project/plans/agent/20261124-0950-the-mcp-client-reads-a-servers-skills/plan.md b/.project/plans/agent/20261124-0950-the-mcp-client-reads-a-servers-skills/plan.md index eea34c0..00eb561 100644 --- a/.project/plans/agent/20261124-0950-the-mcp-client-reads-a-servers-skills/plan.md +++ b/.project/plans/agent/20261124-0950-the-mcp-client-reads-a-servers-skills/plan.md @@ -1,7 +1,7 @@ --- title: The MCP client reads a server's skills domain: agent -status: planned +status: active priority: high created: 2026-11-24 revalidated: 2026-11-24 @@ -49,7 +49,7 @@ The files read and the patterns to reuse are the `refs` above, each with its not | Task | Status | Depends on | | --- | --- | --- | -| [01 - a connection reads skills](task-01-a-connection-reads-skills.md) | todo | - | +| [01 - a connection reads skills](task-01-a-connection-reads-skills.md) | done | - | ## Risks and tradeoffs @@ -57,8 +57,8 @@ The files read and the patterns to reuse are the `refs` above, each with its not ## Resume state -- **Done so far:** nothing. -- **Next action:** [task-01-a-connection-reads-skills.md](task-01-a-connection-reads-skills.md). +- **Done so far:** task 01, on 2026-11-24. +- **Next action:** Softov's review, then `status: built`. - **Open questions:** none. - **Watch out for:** a skill's supporting files are read by URI and are not in `resources/list`. diff --git a/.project/plans/agent/20261124-0950-the-mcp-client-reads-a-servers-skills/task-01-a-connection-reads-skills.md b/.project/plans/agent/20261124-0950-the-mcp-client-reads-a-servers-skills/task-01-a-connection-reads-skills.md index d132707..31ed193 100644 --- a/.project/plans/agent/20261124-0950-the-mcp-client-reads-a-servers-skills/task-01-a-connection-reads-skills.md +++ b/.project/plans/agent/20261124-0950-the-mcp-client-reads-a-servers-skills/task-01-a-connection-reads-skills.md @@ -1,6 +1,6 @@ --- title: A connection reads skills -status: todo +status: done depends: [] layer: "mcp-client" refs: @@ -18,6 +18,7 @@ refs: - `UPDATE: packages/mcp-client/src/types.ts` - `McpSkillInfo` and `McpResourceContents`. - `UPDATE: packages/mcp-client/src/index.ts` - export the new types. - `UPDATE: packages/mcp-client/src/connect.test.ts` - the skill cases. +- `CREATE: packages/mcp-client/test-fixtures/skills-server.mjs` - a stdio server with the extension. ## Steps @@ -35,3 +36,5 @@ refs: - `pnpm test` passes in the repository. ## Resume + +Done on 2026-11-24. `SKILLS_EXTENSION` names the key. The fake connection in `capability.test.ts` gained the new members. The fixture is `test-fixtures/skills-server.mjs`, and the README has a *Skills* section. diff --git a/packages/mcp-client/README.md b/packages/mcp-client/README.md index d089534..bd7fc6c 100644 --- a/packages/mcp-client/README.md +++ b/packages/mcp-client/README.md @@ -55,4 +55,12 @@ An entry with a `url` and no `type` is refused, as in Claude Code. - Over HTTP, the session id and the agreed protocol version go on every request; the GET stream is not opened, and a server that forgets the session closes the connection until the next `tools()`. - `status()` gives each server's state for a host that shows it; `close()` ends every connection. -OAuth sign-in, the SSE transport, resources and prompts are not supported. +## Skills + +A connection from `connectMcp` reads the skills a server serves through the skills extension, [SEP-2640](https://modelcontextprotocol.io/seps/2640-skills-extension). + +- `servesSkills` says whether the server declares the extension and `resources`. +- `skills()` lists every page of `skills/list`; it answers none, and sends nothing, to a server without the extension. +- `skill(uri)` gets one skill by its `SKILL.md` URI, and `read(uri)` reads one file with `resources/read`. + +OAuth sign-in, the SSE transport, prompts and resources other than a skill's files are not supported. diff --git a/packages/mcp-client/src/capability.test.ts b/packages/mcp-client/src/capability.test.ts index 97fdb29..c2384e1 100644 --- a/packages/mcp-client/src/capability.test.ts +++ b/packages/mcp-client/src/capability.test.ts @@ -19,8 +19,11 @@ const fixture = (name: string): string => fileURLToPath(new URL(`../test-fixture /** A connection whose tools and answers a test writes. */ function fake(tools: McpToolInfo[], answer: (tool: string, input: unknown) => McpCallResult = () => ({ content: [] })): McpConnection { return { - name: 'fake', serverInfo: {}, instructions: undefined, closed: undefined, + name: 'fake', serverInfo: {}, instructions: undefined, closed: undefined, capabilities: {}, servesSkills: false, tools: () => tools, + skills: async () => [], + skill: async (uri) => { throw new Error(`no skill ${uri}`); }, + read: async () => [], call: async (tool, input) => answer(tool, input), close: async () => {}, }; diff --git a/packages/mcp-client/src/connect.test.ts b/packages/mcp-client/src/connect.test.ts index bb70e8c..c852c22 100644 --- a/packages/mcp-client/src/connect.test.ts +++ b/packages/mcp-client/src/connect.test.ts @@ -84,3 +84,33 @@ describe('launchOf', () => { } }); }); + +describe('connectMcp reads a server\'s skills (SEP-2640)', () => { + it('lists every page of skills, gets one, and reads its files', async () => { + const connection = await connectMcp({ name: 'skills', server: { command: process.execPath, args: [fixture('skills-server.mjs')] }, clientInfo, timeoutMs: 10_000 }); + try { + expect(connection.servesSkills).toBe(true); + const skills = await connection.skills(); + expect(skills.map((one) => one.frontmatter.name)).toEqual(['one', 'two']); + expect(skills[1]!.resources).toHaveLength(2); + const two = await connection.skill('skill://two/SKILL.md'); + expect(two.frontmatter).toMatchObject({ name: 'two', description: 'The two skill' }); + expect(await connection.read('skill://two/notes.md')).toEqual([{ uri: 'skill://two/notes.md', mimeType: 'text/markdown', text: 'Notes.' }]); + await expect(connection.skill('skill://none/SKILL.md')).rejects.toThrow('no skill'); + } finally { + await connection.close(); + } + }); + + it('answers no skills, and sends no call, to a server without the extension', async () => { + const connection = await connectMcp({ name: 'plain', server: { command: process.execPath, args: [fixture('skills-server.mjs')], env: { SKILLS_OFF: '1' } }, clientInfo, timeoutMs: 10_000 }); + try { + expect(connection.servesSkills).toBe(false); + expect(await connection.skills()).toEqual([]); + const state = (await connection.call('calls', {})).structuredContent as { calls: string[] }; + expect(state.calls).not.toContain('skills/list'); + } finally { + await connection.close(); + } + }); +}); diff --git a/packages/mcp-client/src/connect.ts b/packages/mcp-client/src/connect.ts index df6f5d1..b899d79 100644 --- a/packages/mcp-client/src/connect.ts +++ b/packages/mcp-client/src/connect.ts @@ -1,11 +1,14 @@ import { createHttpTransport } from './http.js'; import { createRpcClient, messageOf } from './rpc.js'; import { createStdioTransport } from './stdio.js'; -import type { McpCallResult, McpClientInfo, McpServerConfig, McpToolInfo, Transport } from './types.js'; +import type { McpCallResult, McpClientInfo, McpResourceContents, McpServerConfig, McpSkillInfo, McpToolInfo, Transport } from './types.js'; /** The versions this client speaks, newest first; `initialize` asks for the first. */ export const PROTOCOL_VERSIONS = ['2025-11-25', '2025-06-18', '2025-03-26', '2024-11-05']; +/** The key a server declares the skills extension under, in `capabilities.extensions` (SEP-2640). */ +export const SKILLS_EXTENSION = 'io.modelcontextprotocol/skills'; + /** One server, initialized, with its tools listed. */ export interface McpConnection { readonly name: string; @@ -15,6 +18,16 @@ export interface McpConnection { /** The tools as last listed; a `list_changed` lists them again. */ tools(): McpToolInfo[]; call(tool: string, input: unknown, options?: { signal?: AbortSignal; timeoutMs?: number }): Promise; + /** What the server said it can do at `initialize`. */ + readonly capabilities: Record; + /** Whether the server declares the skills extension (SEP-2640) and resources, so the skill calls below are served. */ + readonly servesSkills: boolean; + /** Every skill the server lists, every page; none, and no call, when it does not serve skills. */ + skills(options?: { timeoutMs?: number }): Promise; + /** One skill by its `SKILL.md` URI, listed or not. */ + skill(uri: string, options?: { timeoutMs?: number }): Promise; + /** A resource's contents, by `resources/read`. */ + read(uri: string, options?: { timeoutMs?: number }): Promise; /** Why the connection closed; undefined while it is open. */ readonly closed: string | undefined; close(): Promise; @@ -67,7 +80,7 @@ export async function connectMcp(options: ConnectOptions): Promise }; } | null; const version = answer?.protocolVersion; if (typeof version !== 'string' || !PROTOCOL_VERSIONS.includes(version)) { @@ -76,6 +89,10 @@ export async function connectMcp(options: ConnectOptions): Promise = answer?.capabilities ?? {}; + // SEP-2640: the extension under `capabilities.extensions`, which a server MUST pair with `resources`. + // https://modelcontextprotocol.io/seps/2640-skills-extension + const servesSkills = answer?.capabilities?.extensions?.[SKILLS_EXTENSION] !== undefined && answer.capabilities.resources !== undefined; return { name, serverInfo: answer?.serverInfo ?? {}, @@ -85,6 +102,28 @@ export async function connectMcp(options: ConnectOptions): Promise transport.close(), }; diff --git a/packages/mcp-client/src/index.ts b/packages/mcp-client/src/index.ts index b68b9ec..2194157 100644 --- a/packages/mcp-client/src/index.ts +++ b/packages/mcp-client/src/index.ts @@ -1,6 +1,6 @@ export { createMcpClients } from './capability.js'; export type { McpClients, McpClientsOptions, McpServerState } from './capability.js'; -export { connectMcp, PROTOCOL_VERSIONS } from './connect.js'; +export { connectMcp, PROTOCOL_VERSIONS, SKILLS_EXTENSION } from './connect.js'; export type { ConnectOptions, McpConnection } from './connect.js'; export { effectsOf } from './effects.js'; export { expandServer } from './expand.js'; @@ -12,5 +12,5 @@ export { McpError } from './rpc.js'; export { MCP_SERVERS_SCHEMA, serversOf } from './schema.js'; export { createStdioTransport, launchOf } from './stdio.js'; export type { - JsonRpcMessage, McpCallResult, McpClientInfo, McpContent, McpHttpServer, McpServerConfig, McpStdioServer, McpToolAnnotations, McpToolInfo, Transport, + JsonRpcMessage, McpCallResult, McpClientInfo, McpContent, McpHttpServer, McpResourceContents, McpServerConfig, McpSkillInfo, McpSkillResource, McpStdioServer, McpToolAnnotations, McpToolInfo, Transport, } from './types.js'; diff --git a/packages/mcp-client/src/types.ts b/packages/mcp-client/src/types.ts index 94d31f8..1c174ea 100644 --- a/packages/mcp-client/src/types.ts +++ b/packages/mcp-client/src/types.ts @@ -61,6 +61,36 @@ export interface McpCallResult { isError?: boolean; } +/** One file of a served skill, as `skills/list` and `skills/get` give it (SEP-2640). */ +export interface McpSkillResource { + uri: string; + /** `sha256:` and 64 lowercase hex digits. */ + digest: string; + /** Bytes of the raw content. */ + size: number; +} + +/** + * One skill a server serves, as `skills/list` and `skills/get` give it (SEP-2640). + * https://modelcontextprotocol.io/seps/2640-skills-extension + */ +export interface McpSkillInfo { + /** The skill's `SKILL.md`. */ + uri: string; + /** The `SKILL.md` front matter, as JSON; `name` and `description` by the Agent Skills format. */ + frontmatter: { name?: string; description?: string; [key: string]: unknown }; + /** Every file of the skill, or `dynamic` when the server cannot list them ahead. */ + resources: McpSkillResource[] | 'dynamic'; +} + +/** One entry of what `resources/read` answers: text or base64 bytes. */ +export interface McpResourceContents { + uri: string; + mimeType?: string; + text?: string; + blob?: string; +} + /** Who this client is, as `initialize` tells the server. */ export interface McpClientInfo { name: string; diff --git a/packages/mcp-client/test-fixtures/skills-server.mjs b/packages/mcp-client/test-fixtures/skills-server.mjs new file mode 100644 index 0000000..390a433 --- /dev/null +++ b/packages/mcp-client/test-fixtures/skills-server.mjs @@ -0,0 +1,51 @@ +// A hand-written stdio server with the skills extension (SEP-2640): two pages of skills, skills/get, resources/read. +// SKILLS_OFF=1 drops the extension. +import { createInterface } from 'node:readline'; + +const send = (message) => process.stdout.write(`${JSON.stringify({ jsonrpc: '2.0', ...message })}\n`); +const skill = (name, files) => ({ + uri: `skill://${name}/SKILL.md`, + frontmatter: { name, description: `The ${name} skill` }, + resources: files.map((file) => ({ uri: `skill://${name}/${file}`, digest: `sha256:${'0'.repeat(64)}`, size: 1 })), +}); +const skills = [skill('one', ['SKILL.md']), skill('two', ['SKILL.md', 'notes.md'])]; +const files = { 'skill://one/SKILL.md': '---\nname: one\n---\nOne.', 'skill://two/SKILL.md': '---\nname: two\n---\nTwo.', 'skill://two/notes.md': 'Notes.' }; +const calls = []; +createInterface({ input: process.stdin }).on('line', (line) => { + const message = JSON.parse(line); + if (message.method !== undefined && message.id !== undefined) calls.push(message.method); + switch (message.method) { + case 'initialize': + send({ id: message.id, result: { + protocolVersion: message.params.protocolVersion, + capabilities: process.env.SKILLS_OFF === '1' ? { tools: {} } : { tools: {}, resources: {}, extensions: { 'io.modelcontextprotocol/skills': {} } }, + serverInfo: { name: 'skills', version: '1' }, + } }); + break; + case 'tools/list': + send({ id: message.id, result: { tools: [{ name: 'calls', description: 'The methods called so far', inputSchema: { type: 'object' } }] } }); + break; + case 'tools/call': + send({ id: message.id, result: { structuredContent: { calls } } }); + break; + case 'skills/list': { + const second = message.params?.cursor === 'two'; + send({ id: message.id, result: { resultType: 'complete', skills: second ? skills.slice(1) : skills.slice(0, 1), ...(second ? {} : { nextCursor: 'two' }) } }); + break; + } + case 'skills/get': { + const found = skills.find((one) => one.uri === message.params.uri); + if (found) send({ id: message.id, result: { resultType: 'complete', skill: found } }); + else send({ id: message.id, error: { code: -32602, message: `no skill ${message.params.uri}` } }); + break; + } + case 'resources/read': { + const text = files[message.params.uri]; + if (text === undefined) send({ id: message.id, error: { code: -32002, message: 'not found' } }); + else send({ id: message.id, result: { contents: [{ uri: message.params.uri, mimeType: 'text/markdown', text }] } }); + break; + } + default: + if (message.id !== undefined) send({ id: message.id, error: { code: -32601, message: 'nope' } }); + } +});