Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -49,16 +49,16 @@ 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

- SEP-2640 may still change its wire - the types follow the SEP page on the day of the build, and the code cites the page.

## 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`.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: A connection reads skills
status: todo
status: done
depends: []
layer: "mcp-client"
refs:
Expand All @@ -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

Expand All @@ -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.
10 changes: 9 additions & 1 deletion packages/mcp-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
5 changes: 4 additions & 1 deletion packages/mcp-client/src/capability.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {},
};
Expand Down
30 changes: 30 additions & 0 deletions packages/mcp-client/src/connect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
});
43 changes: 41 additions & 2 deletions packages/mcp-client/src/connect.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<McpCallResult>;
/** What the server said it can do at `initialize`. */
readonly capabilities: Record<string, unknown>;
/** 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<McpSkillInfo[]>;
/** One skill by its `SKILL.md` URI, listed or not. */
skill(uri: string, options?: { timeoutMs?: number }): Promise<McpSkillInfo>;
/** A resource's contents, by `resources/read`. */
read(uri: string, options?: { timeoutMs?: number }): Promise<McpResourceContents[]>;
/** Why the connection closed; undefined while it is open. */
readonly closed: string | undefined;
close(): Promise<void>;
Expand Down Expand Up @@ -67,7 +80,7 @@ export async function connectMcp(options: ConnectOptions): Promise<McpConnection

try {
const answer = (await rpc.request('initialize', { protocolVersion: PROTOCOL_VERSIONS[0], capabilities: {}, clientInfo: options.clientInfo }, timeout)) as {
protocolVersion?: string; serverInfo?: { name?: string; version?: string }; instructions?: string; capabilities?: { tools?: unknown };
protocolVersion?: string; serverInfo?: { name?: string; version?: string }; instructions?: string; capabilities?: { tools?: unknown; resources?: unknown; extensions?: Record<string, unknown> };
} | null;
const version = answer?.protocolVersion;
if (typeof version !== 'string' || !PROTOCOL_VERSIONS.includes(version)) {
Expand All @@ -76,6 +89,10 @@ export async function connectMcp(options: ConnectOptions): Promise<McpConnection
transport.agreed?.(version);
await rpc.notify('notifications/initialized');
if (answer?.capabilities?.tools !== undefined) await listAll();
const capabilities: Record<string, unknown> = 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 ?? {},
Expand All @@ -85,6 +102,28 @@ export async function connectMcp(options: ConnectOptions): Promise<McpConnection
await listing;
return (await rpc.request('tools/call', { name: tool, arguments: input ?? {} }, callOptions)) as McpCallResult;
},
capabilities,
servesSkills,
async skills(skillOptions = {}) {
if (!servesSkills) return [];
const found: McpSkillInfo[] = [];
let cursor: string | undefined;
do {
const page = (await rpc.request('skills/list', cursor !== undefined ? { cursor } : {}, (skillOptions.timeoutMs !== undefined ? { timeoutMs: skillOptions.timeoutMs } : timeout))) as { skills?: McpSkillInfo[]; nextCursor?: string } | null;
found.push(...(page?.skills ?? []));
cursor = typeof page?.nextCursor === 'string' && page.nextCursor !== '' ? page.nextCursor : undefined;
} while (cursor !== undefined);
return found;
},
async skill(uri, skillOptions = {}) {
const answer = (await rpc.request('skills/get', { uri }, (skillOptions.timeoutMs !== undefined ? { timeoutMs: skillOptions.timeoutMs } : timeout))) as { skill?: McpSkillInfo } | null;
if (answer?.skill === undefined) throw new Error(`the server answered skills/get for ${uri} with no skill`);
return answer.skill;
},
async read(uri, readOptions = {}) {
const answer = (await rpc.request('resources/read', { uri }, (readOptions.timeoutMs !== undefined ? { timeoutMs: readOptions.timeoutMs } : timeout))) as { contents?: McpResourceContents[] } | null;
return answer?.contents ?? [];
},
get closed() { return rpc.closed; },
close: () => transport.close(),
};
Expand Down
4 changes: 2 additions & 2 deletions packages/mcp-client/src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';
30 changes: 30 additions & 0 deletions packages/mcp-client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
51 changes: 51 additions & 0 deletions packages/mcp-client/test-fixtures/skills-server.mjs
Original file line number Diff line number Diff line change
@@ -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' } });
}
});
Loading