@contractspec/lib.contracts-runtime-server-mcp 2.9.1 → 3.1.1
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/LICENSE +21 -0
- package/README.md +104 -1
- package/package.json +6 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Chaman Ventures, SASU
|
|
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,106 @@
|
|
|
1
1
|
# @contractspec/lib.contracts-runtime-server-mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
MCP runtime adapters for projecting ContractSpec registries into an MCP server.
|
|
4
|
+
|
|
5
|
+
Website: https://contractspec.io/
|
|
6
|
+
|
|
7
|
+
## Why this package exists
|
|
8
|
+
|
|
9
|
+
This package is the MCP-specific runtime layer split from `@contractspec/lib.contracts`.
|
|
10
|
+
|
|
11
|
+
It converts contract registries into MCP capabilities:
|
|
12
|
+
|
|
13
|
+
- command operations -> MCP tools
|
|
14
|
+
- resource templates -> MCP resources
|
|
15
|
+
- prompt specs -> MCP prompts
|
|
16
|
+
- presentation specs -> MCP resources (optional)
|
|
17
|
+
|
|
18
|
+
## Package boundary (important)
|
|
19
|
+
|
|
20
|
+
Use this package for:
|
|
21
|
+
|
|
22
|
+
- Registering ContractSpec operations/resources/prompts/presentations on an MCP server.
|
|
23
|
+
- Reusing standardized MCP naming and registration behavior.
|
|
24
|
+
|
|
25
|
+
Do not use this package for:
|
|
26
|
+
|
|
27
|
+
- Defining operation/event specs (use `@contractspec/lib.contracts-spec`).
|
|
28
|
+
- Owning server transport lifecycle (stdio/http wiring stays in your app using MCP SDK).
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm install @contractspec/lib.contracts-runtime-server-mcp @contractspec/lib.contracts-spec @modelcontextprotocol/sdk
|
|
34
|
+
# or
|
|
35
|
+
bun add @contractspec/lib.contracts-runtime-server-mcp @contractspec/lib.contracts-spec @modelcontextprotocol/sdk
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Export map
|
|
39
|
+
|
|
40
|
+
- Main orchestration:
|
|
41
|
+
- `createMcpServer`
|
|
42
|
+
- Context typing:
|
|
43
|
+
- `McpCtxFactories`
|
|
44
|
+
- Fine-grained registration:
|
|
45
|
+
- `registerMcpTools`
|
|
46
|
+
- `registerMcpResources`
|
|
47
|
+
- `registerMcpPrompts`
|
|
48
|
+
- `registerMcpPresentations`
|
|
49
|
+
- Compatibility alias:
|
|
50
|
+
- `provider-mcp` (re-exports `createMcpServer`)
|
|
51
|
+
|
|
52
|
+
## Quick start
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
56
|
+
import {
|
|
57
|
+
OperationSpecRegistry,
|
|
58
|
+
PromptRegistry,
|
|
59
|
+
ResourceRegistry,
|
|
60
|
+
} from "@contractspec/lib.contracts-spec";
|
|
61
|
+
import { Logger } from "@contractspec/lib.logger";
|
|
62
|
+
import {
|
|
63
|
+
createMcpServer,
|
|
64
|
+
type McpCtxFactories,
|
|
65
|
+
} from "@contractspec/lib.contracts-runtime-server-mcp";
|
|
66
|
+
|
|
67
|
+
const server = new McpServer({ name: "contractspec", version: "1.0.0" });
|
|
68
|
+
|
|
69
|
+
const operations = new OperationSpecRegistry();
|
|
70
|
+
const resources = new ResourceRegistry();
|
|
71
|
+
const prompts = new PromptRegistry();
|
|
72
|
+
const logger = new Logger();
|
|
73
|
+
|
|
74
|
+
const ctxFactories: McpCtxFactories = {
|
|
75
|
+
logger,
|
|
76
|
+
toolCtx: () => ({ actor: "agent", channel: "agent" }),
|
|
77
|
+
promptCtx: () => ({ locale: "en" }),
|
|
78
|
+
resourceCtx: () => ({ locale: "en" }),
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
createMcpServer(server, operations, resources, prompts, ctxFactories);
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Behavior details
|
|
85
|
+
|
|
86
|
+
- Only command operations are registered as MCP tools.
|
|
87
|
+
- Resource resolvers support both text and binary payloads (binary is returned as base64 blobs).
|
|
88
|
+
- Prompt args are converted to MCP args schema via Zod compatibility helpers.
|
|
89
|
+
- Presentations are optional: if no presentation registry is passed or it is empty, no presentation resources are registered.
|
|
90
|
+
|
|
91
|
+
## AI assistant guidance
|
|
92
|
+
|
|
93
|
+
When generating code:
|
|
94
|
+
|
|
95
|
+
- Use this package after operation/resource/prompt specs already exist in `@contractspec/lib.contracts-spec`.
|
|
96
|
+
- Start with `createMcpServer` for complete wiring, then drop to `registerMcp*` helpers only for custom registration logic.
|
|
97
|
+
|
|
98
|
+
When debugging:
|
|
99
|
+
|
|
100
|
+
- If tools are missing, verify operations are commands (`meta.kind === "command"`).
|
|
101
|
+
- If resources are missing, verify `ResourceRegistry` contains templates and URI templates are valid.
|
|
102
|
+
|
|
103
|
+
## Split migration from deprecated monolith
|
|
104
|
+
|
|
105
|
+
- `@contractspec/lib.contracts/server/provider-mcp` -> `@contractspec/lib.contracts-runtime-server-mcp/provider-mcp`
|
|
106
|
+
- `@contractspec/lib.contracts/server/mcp/*` -> `@contractspec/lib.contracts-runtime-server-mcp/mcp/*`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contractspec/lib.contracts-runtime-server-mcp",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"description": "MCP server runtime adapters for ContractSpec contracts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -19,15 +19,15 @@
|
|
|
19
19
|
"dev": "contractspec-bun-build dev"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@contractspec/lib.contracts-spec": "
|
|
23
|
-
"@contractspec/lib.logger": "
|
|
24
|
-
"@modelcontextprotocol/sdk": "^1.27.
|
|
22
|
+
"@contractspec/lib.contracts-spec": "3.1.1",
|
|
23
|
+
"@contractspec/lib.logger": "3.1.0",
|
|
24
|
+
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
25
25
|
"zod": "^4.3.5"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@contractspec/tool.typescript": "
|
|
28
|
+
"@contractspec/tool.typescript": "3.1.0",
|
|
29
29
|
"typescript": "^5.9.3",
|
|
30
|
-
"@contractspec/tool.bun": "
|
|
30
|
+
"@contractspec/tool.bun": "3.1.0"
|
|
31
31
|
},
|
|
32
32
|
"files": [
|
|
33
33
|
"dist",
|