@procedures/mcp 0.0.0-stage → 0.2.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.
Files changed (54) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/LICENSE +21 -0
  3. package/README.md +359 -2
  4. package/dist/.tsbuildinfo +1 -0
  5. package/dist/context/index.d.ts +5 -0
  6. package/dist/context/index.d.ts.map +1 -0
  7. package/dist/context/index.js +5 -0
  8. package/dist/context/index.js.map +1 -0
  9. package/dist/context/mcp-context.d.ts +57 -0
  10. package/dist/context/mcp-context.d.ts.map +1 -0
  11. package/dist/context/mcp-context.js +40 -0
  12. package/dist/context/mcp-context.js.map +1 -0
  13. package/dist/index.d.ts +13 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +15 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/mapping/index.d.ts +6 -0
  18. package/dist/mapping/index.d.ts.map +1 -0
  19. package/dist/mapping/index.js +6 -0
  20. package/dist/mapping/index.js.map +1 -0
  21. package/dist/mapping/path-encoder.d.ts +72 -0
  22. package/dist/mapping/path-encoder.d.ts.map +1 -0
  23. package/dist/mapping/path-encoder.js +93 -0
  24. package/dist/mapping/path-encoder.js.map +1 -0
  25. package/dist/mapping/procedure-to-tool.d.ts +47 -0
  26. package/dist/mapping/procedure-to-tool.d.ts.map +1 -0
  27. package/dist/mapping/procedure-to-tool.js +172 -0
  28. package/dist/mapping/procedure-to-tool.js.map +1 -0
  29. package/dist/schema/index.d.ts +5 -0
  30. package/dist/schema/index.d.ts.map +1 -0
  31. package/dist/schema/index.js +5 -0
  32. package/dist/schema/index.js.map +1 -0
  33. package/dist/schema/tool-schema.d.ts +77 -0
  34. package/dist/schema/tool-schema.d.ts.map +1 -0
  35. package/dist/schema/tool-schema.js +103 -0
  36. package/dist/schema/tool-schema.js.map +1 -0
  37. package/dist/schema/zod-to-json-schema.d.ts +58 -0
  38. package/dist/schema/zod-to-json-schema.d.ts.map +1 -0
  39. package/dist/schema/zod-to-json-schema.js +79 -0
  40. package/dist/schema/zod-to-json-schema.js.map +1 -0
  41. package/dist/types.d.ts +111 -0
  42. package/dist/types.d.ts.map +1 -0
  43. package/dist/types.js +8 -0
  44. package/dist/types.js.map +1 -0
  45. package/package.json +63 -3
  46. package/src/context/index.ts +10 -0
  47. package/src/context/mcp-context.ts +80 -0
  48. package/src/index.ts +57 -0
  49. package/src/mapping/index.ts +20 -0
  50. package/src/mapping/path-encoder.ts +103 -0
  51. package/src/mapping/procedure-to-tool.ts +217 -0
  52. package/src/schema/index.ts +15 -0
  53. package/src/schema/tool-schema.ts +135 -0
  54. package/src/types.ts +120 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,26 @@
1
+ # @procedures/mcp
2
+
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 0cf4bea: **Invocation capabilities** (packages/documentation/CAPABILITIES-2026-10.md, the guide is client/docs/CAPABILITIES.md). Each call operates with a capability: a clearance, permitted effects and a deadline. A nested call gets the same capability or a narrower one.
8
+
9
+ - Procedures declare `metadata.effects` (`reads`, `writes`, `destructive`, `idempotent`). Each procedure of these packages declares them.
10
+ - `hostPolicy({ capability, readOnly, clearanceOrder, resources, admitItem })`, and `new Client({ capability })`. A refused call gives `FORBIDDEN` (HTTP 403) with a reason.
11
+ - `ctx.capability` and `ctx.resources` are new required fields of `ProcedureContext`. A test that makes a context by hand adds `capability: {}` and `resources: {}`.
12
+ - An application gives its clearance and resource types by augmenting `Register`.
13
+ - The timeout interceptor sets the deadline of the capability, and a remote call sends the remaining time.
14
+ - The MCP tools have hints (`readOnlyHint`, `destructiveHint`, `idempotentHint`, `openWorldHint`) from the effects. `mark mcp --read-only` (or `MCP_READ_ONLY=1`) serves only the tools that change nothing.
15
+ - **Breaking:** `git.remote` only reads the URL. `git.remote.set` sets it (before: `git.remote` with `url`).
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies [0cf4bea]
20
+ - Updated dependencies [44d3e30]
21
+ - Updated dependencies [76d0d64]
22
+ - @procedures/client@0.2.0
23
+
24
+ ## 0.1.0
25
+
26
+ The first release on npm. The packages of the client monorepo have one version together.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-2026 Mark Russell
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,360 @@
1
- # Temporary Holding Version
1
+ # @procedures/mcp
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm](https://img.shields.io/npm/v/@procedures/mcp?color=2346c4&label=npm)](https://www.npmjs.com/package/@procedures/mcp)
4
+
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.9-blue.svg)](https://www.typescriptlang.org/)
7
+ [![Node.js](https://img.shields.io/badge/Node.js-%3E%3D22-green.svg)](https://nodejs.org/)
8
+ [![MCP](https://img.shields.io/badge/MCP-Protocol-purple.svg)](https://modelcontextprotocol.io/)
9
+
10
+ > Core types and utilities for MCP (Model Context Protocol) integration. Converts Zod schemas and procedures to MCP-compatible formats.
11
+
12
+ ## Table of Contents
13
+
14
+ - [Overview](#overview)
15
+ - [Installation](#installation)
16
+ - [Architecture](#architecture)
17
+ - [Quick Start](#quick-start)
18
+ - [API Reference](#api-reference)
19
+ - [zodToJsonSchema](#zodtojsonschema)
20
+ - [procedureToMcpTool](#proceduretomcptool)
21
+ - [proceduresToMcpTools](#procedurestomcptools)
22
+ - [Tool Filtering](#tool-filtering)
23
+ - [Integration](#integration)
24
+ - [Requirements](#requirements)
25
+ - [License](#license)
26
+
27
+ ---
28
+
29
+ ## Overview
30
+
31
+ **mcp** provides the foundation for MCP integration:
32
+
33
+ - **Schema Conversion** - Convert Zod schemas to JSON Schema format
34
+ - **Procedure Mapping** - Transform procedures to MCP tool definitions
35
+ - **Filtering** - Control which procedures become MCP tools
36
+ - **Type Definitions** - TypeScript types for MCP tools and filters
37
+
38
+ ---
39
+
40
+ ## Installation
41
+
42
+ ```bash
43
+ npm install @procedures/mcp
44
+ ```
45
+
46
+ ---
47
+
48
+ ## Architecture
49
+
50
+ ### Conversion Pipeline
51
+
52
+ ```mermaid
53
+ graph LR
54
+ subgraph "Input"
55
+ Proc[Procedure]
56
+ Zod[Zod Schema]
57
+ end
58
+
59
+ subgraph "mcp Package"
60
+ Z2J[zodToJsonSchema]
61
+ P2T[procedureToMcpTool]
62
+ end
63
+
64
+ subgraph "Output"
65
+ JSON[JSON Schema]
66
+ Tool[MCP Tool]
67
+ end
68
+
69
+ Zod --> Z2J
70
+ Z2J --> JSON
71
+ Proc --> P2T
72
+ JSON --> P2T
73
+ P2T --> Tool
74
+ ```
75
+
76
+ ### Procedure to MCP Tool Mapping
77
+
78
+ ```mermaid
79
+ graph TB
80
+ subgraph "Procedure"
81
+ Path[path: string[]]
82
+ Meta[metadata.description]
83
+ Input[input: ZodSchema]
84
+ Handler[handler: Function]
85
+ end
86
+
87
+ subgraph "MCP Tool"
88
+ Name[name: string]
89
+ Desc[description: string]
90
+ Schema[inputSchema: JSONSchema]
91
+ end
92
+
93
+ Path -->|"join('.')"| Name
94
+ Meta --> Desc
95
+ Input -->|zodToJsonSchema| Schema
96
+ ```
97
+
98
+ ### System Integration
99
+
100
+ ```mermaid
101
+ graph TB
102
+ subgraph "Procedure Registry"
103
+ R1[fs.read]
104
+ R2[git.commit]
105
+ R3[shell.run]
106
+ R4[...]
107
+ end
108
+
109
+ subgraph "mcp"
110
+ Convert[proceduresToMcpTools]
111
+ Filter[McpToolFilter]
112
+ end
113
+
114
+ subgraph "client-mcp"
115
+ Transport[McpServerTransport]
116
+ end
117
+
118
+ subgraph "Claude"
119
+ Tools[MCP Tools]
120
+ end
121
+
122
+ R1 --> Convert
123
+ R2 --> Convert
124
+ R3 --> Convert
125
+ R4 --> Convert
126
+ Filter --> Convert
127
+ Convert --> Transport
128
+ Transport --> Tools
129
+ ```
130
+
131
+ ---
132
+
133
+ ## Quick Start
134
+
135
+ ```typescript
136
+ import { proceduresToMcpTools, zodToJsonSchema } from "@procedures/mcp";
137
+ import { PROCEDURE_REGISTRY } from "@procedures/client";
138
+
139
+ // Convert all registered procedures to MCP tools
140
+ const tools = proceduresToMcpTools(PROCEDURE_REGISTRY.getAll());
141
+
142
+ // Convert a Zod schema to JSON Schema
143
+ const jsonSchema = zodToJsonSchema(myZodSchema);
144
+ ```
145
+
146
+ ---
147
+
148
+ ## API Reference
149
+
150
+ ### zodToJsonSchema
151
+
152
+ Converts a Zod schema to JSON Schema format for MCP tool input definitions.
153
+
154
+ ```typescript
155
+ function zodToJsonSchema(schema: ZodType): JsonSchema;
156
+ ```
157
+
158
+ **Supported Zod Types:**
159
+
160
+ | Zod Type | JSON Schema |
161
+ |----------|-------------|
162
+ | `z.string()` | `{ type: "string" }` |
163
+ | `z.number()` | `{ type: "number" }` |
164
+ | `z.boolean()` | `{ type: "boolean" }` |
165
+ | `z.array()` | `{ type: "array", items: ... }` |
166
+ | `z.object()` | `{ type: "object", properties: ... }` |
167
+ | `z.enum()` | `{ type: "string", enum: [...] }` |
168
+ | `z.optional()` | Removes from `required` |
169
+ | `z.default()` | Adds `default` value |
170
+ | `z.describe()` | Adds `description` |
171
+
172
+ **Example:**
173
+ ```typescript
174
+ import { z } from "zod";
175
+ import { zodToJsonSchema } from "@procedures/mcp";
176
+
177
+ const schema = z.object({
178
+ path: z.string().describe("File path"),
179
+ encoding: z.enum(["utf8", "base64"]).default("utf8"),
180
+ });
181
+
182
+ const jsonSchema = zodToJsonSchema(schema);
183
+ // {
184
+ // type: "object",
185
+ // properties: {
186
+ // path: { type: "string", description: "File path" },
187
+ // encoding: { type: "string", enum: ["utf8", "base64"], default: "utf8" }
188
+ // },
189
+ // required: ["path"]
190
+ // }
191
+ ```
192
+
193
+ ---
194
+
195
+ ### procedureToMcpTool
196
+
197
+ Converts a single procedure to an MCP tool definition.
198
+
199
+ ```typescript
200
+ function procedureToMcpTool(procedure: Procedure): McpTool;
201
+
202
+ interface McpTool {
203
+ name: string; // Dot-joined path: "fs.read"
204
+ description: string; // From procedure metadata
205
+ inputSchema: JsonSchema; // Converted from Zod
206
+ }
207
+ ```
208
+
209
+ **Example:**
210
+ ```typescript
211
+ const tool = procedureToMcpTool(fsReadProcedure);
212
+ // {
213
+ // name: "fs.read",
214
+ // description: "Read file contents",
215
+ // inputSchema: { type: "object", properties: { path: ... } }
216
+ // }
217
+ ```
218
+
219
+ ---
220
+
221
+ ### proceduresToMcpTools
222
+
223
+ Converts multiple procedures to MCP tools with optional filtering.
224
+
225
+ ```typescript
226
+ function proceduresToMcpTools(
227
+ procedures: Procedure[],
228
+ filter?: McpToolFilter
229
+ ): McpTool[];
230
+ ```
231
+
232
+ **Example:**
233
+ ```typescript
234
+ // Convert all procedures
235
+ const allTools = proceduresToMcpTools(PROCEDURE_REGISTRY.getAll());
236
+
237
+ // Convert with filtering
238
+ const filteredTools = proceduresToMcpTools(procedures, {
239
+ includeTags: ["fs", "git"],
240
+ excludeInternal: true,
241
+ });
242
+ ```
243
+
244
+ ---
245
+
246
+ ## Tool Filtering
247
+
248
+ Control which procedures are exposed as MCP tools:
249
+
250
+ ```typescript
251
+ interface McpToolFilter {
252
+ includeTags?: string[]; // Only include procedures with these tags
253
+ excludeTags?: string[]; // Exclude procedures with these tags
254
+ excludeInternal?: boolean; // Exclude procedures starting with _
255
+ pathPrefix?: string[]; // Only include procedures with this path prefix
256
+ include?: (path: string[]) => boolean; // Only the procedures for which it gives true
257
+ }
258
+ ```
259
+
260
+ ### Filter Examples
261
+
262
+ ```mermaid
263
+ graph TB
264
+ subgraph "Original (10 procedures)"
265
+ All[fs.read, fs.write, git.commit,<br/>_internal.debug, api.users, ...]
266
+ end
267
+
268
+ subgraph "excludeInternal: true"
269
+ NoInt[fs.read, fs.write, git.commit,<br/>api.users, ...]
270
+ end
271
+
272
+ subgraph "pathPrefix: ['fs']"
273
+ FSOnly[fs.read, fs.write]
274
+ end
275
+
276
+ subgraph "includeTags: ['public']"
277
+ Public[Tagged as public only]
278
+ end
279
+
280
+ All --> NoInt
281
+ All --> FSOnly
282
+ All --> Public
283
+ ```
284
+
285
+ **Usage:**
286
+ ```typescript
287
+ import { proceduresToMcpTools, type McpToolFilter } from "@procedures/mcp";
288
+
289
+ const filter: McpToolFilter = {
290
+ includeTags: ["fs", "git"], // Only the procedures with these tags
291
+ excludeTags: ["internal"], // Exclude internal
292
+ excludeInternal: true, // Exclude _prefixed
293
+ pathPrefix: ["fs"], // Only fs.* procedures
294
+ };
295
+
296
+ const tools = proceduresToMcpTools(procedures, filter);
297
+ ```
298
+
299
+ ---
300
+
301
+ ## Integration
302
+
303
+ ### With client-mcp
304
+
305
+ ```typescript
306
+ import { McpServerTransport } from "@procedures/mcp-server";
307
+ import { proceduresToMcpTools } from "@procedures/mcp";
308
+
309
+ // client-mcp uses mcp internally
310
+ const transport = new McpServerTransport(server, {
311
+ transport: "stdio",
312
+ // Filter uses McpToolFilter from mcp package
313
+ filter: {
314
+ excludeInternal: true,
315
+ },
316
+ });
317
+ ```
318
+
319
+ ### Package Hierarchy
320
+
321
+ ```mermaid
322
+ graph BT
323
+ subgraph "Implementation"
324
+ Impl[impl-mcp-dev]
325
+ end
326
+
327
+ subgraph "Transport"
328
+ ClientMCP[client-mcp]
329
+ end
330
+
331
+ subgraph "Core"
332
+ MCP[mcp]
333
+ Client[client]
334
+ end
335
+
336
+ subgraph "External"
337
+ SDK[@modelcontextprotocol/sdk]
338
+ end
339
+
340
+ Impl --> ClientMCP
341
+ ClientMCP --> MCP
342
+ ClientMCP --> Client
343
+ MCP --> Client
344
+ ClientMCP --> SDK
345
+ ```
346
+
347
+ ---
348
+
349
+ ## Requirements
350
+
351
+ - **Node.js** >= 22
352
+ - **Dependencies:**
353
+ - `@procedures/client`
354
+ - `zod`
355
+
356
+ ---
357
+
358
+ ## License
359
+
360
+ MIT