@xyd-js/mcp 0.0.0-build-9f87f13-20250930210637
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 +89 -0
- package/dist/index.js +149918 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) LiveSession Sp.z.o.o
|
|
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
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# @xyd-js/mcp
|
|
2
|
+
|
|
3
|
+
Utilities for building Model Context Protocol (MCP) servers in the xyd ecosystem.
|
|
4
|
+
|
|
5
|
+
This package exposes helpers to:
|
|
6
|
+
|
|
7
|
+
- Register API Reference resources (as Markdown) derived from a Uniform source
|
|
8
|
+
- Register callable MCP tools from OpenAPI or GraphQL specs with structured input schemas
|
|
9
|
+
|
|
10
|
+
Currently supported Uniform sources:
|
|
11
|
+
|
|
12
|
+
- OpenAPI: `.json`, `.yaml`, `.yml`
|
|
13
|
+
- GraphQL schema files: `.graphql`, `.graphqls`
|
|
14
|
+
|
|
15
|
+
Typescript/React sources are not supported yet.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
bun add @xyd-js/mcp
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Peer/runtime requirements: Bun or Node.js compatible ESM environment.
|
|
24
|
+
|
|
25
|
+
## API
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
29
|
+
import { mcpUniformResources, mcpUniformTools } from "@xyd-js/mcp";
|
|
30
|
+
|
|
31
|
+
const server = new McpServer({ name: "xyd-mcp", version: "0.1.0" });
|
|
32
|
+
|
|
33
|
+
// Path to a Uniform source (OpenAPI JSON/YAML or GraphQL schema)
|
|
34
|
+
const uniformSource = "./openapi.json";
|
|
35
|
+
|
|
36
|
+
// Register API reference resources (text/markdown) under uri: api-reference://<canonical>
|
|
37
|
+
await mcpUniformResources(server, uniformSource);
|
|
38
|
+
|
|
39
|
+
// Register tools; if your API needs auth, pass a token which will be sent
|
|
40
|
+
// as Authorization: Bearer <token> for outgoing requests
|
|
41
|
+
await mcpUniformTools(server, uniformSource, process.env.API_TOKEN || "");
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### `mcpUniformResources(server, uniformSource)`
|
|
45
|
+
|
|
46
|
+
Generates Markdown API reference pages from the provided Uniform source and registers them as MCP resources using `api-reference://<canonical>` URIs with `mimeType: text/markdown`.
|
|
47
|
+
|
|
48
|
+
### `mcpUniformTools(server, uniformSource, token)`
|
|
49
|
+
|
|
50
|
+
Creates MCP tools for each operation discovered in the Uniform source. Tool input schemas are derived from the API definition and grouped by:
|
|
51
|
+
|
|
52
|
+
- `pathParams`
|
|
53
|
+
- `queryParams`
|
|
54
|
+
- `headers`
|
|
55
|
+
- `requestBody`
|
|
56
|
+
|
|
57
|
+
When a tool is invoked it will:
|
|
58
|
+
|
|
59
|
+
- Perform a fetch using the operation method and URL
|
|
60
|
+
- Include `Authorization: Bearer <token>` if a token was provided
|
|
61
|
+
- Return both a `resource_link` to the associated API reference and the JSON response (as text)
|
|
62
|
+
|
|
63
|
+
## Uniform Source Detection
|
|
64
|
+
|
|
65
|
+
`uniformSource` can be any of:
|
|
66
|
+
|
|
67
|
+
- OpenAPI spec: `.json`, `.yaml`, `.yml`
|
|
68
|
+
- GraphQL schema: `.graphql`, `.graphqls`
|
|
69
|
+
|
|
70
|
+
If the extension cannot be detected or the source cannot be loaded, no tools/resources will be registered.
|
|
71
|
+
|
|
72
|
+
## Example
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
76
|
+
import { mcpUniformResources, mcpUniformTools } from "@xyd-js/mcp";
|
|
77
|
+
|
|
78
|
+
const server = new McpServer({ name: "example", version: "0.0.0" });
|
|
79
|
+
await mcpUniformResources(server, "./demo/simple/openapi.json");
|
|
80
|
+
await mcpUniformTools(server, "./demo/simple/openapi.json", "my-access-token");
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Notes
|
|
84
|
+
|
|
85
|
+
- Responses are currently assumed to be JSON when returning tool results.
|
|
86
|
+
- Markdown rendering uses xyd components highlighting where possible.
|
|
87
|
+
- This library is ESM-only.
|
|
88
|
+
|
|
89
|
+
|