@xyd-js/mcp-server 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/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # @xyd-js/mcp-server
2
+
3
+ ## 0.0.0-build-9f87f13-20250930210637
4
+
5
+ ### Patch Changes
6
+
7
+ - update all packages
8
+ - Updated dependencies
9
+ - @xyd-js/mcp@0.0.0-build-9f87f13-20250930210637
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-server
2
+
3
+ HTTP MCP server for the xyd ecosystem. Serves Model Context Protocol endpoints over HTTP and wires tools/resources from a Uniform source (OpenAPI or GraphQL).
4
+
5
+ Powered by `express` and `@modelcontextprotocol/sdk` with support for the MCP Inspector.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ bun install
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ Build the server and run it, pointing to a Uniform source file. The server binds to `PORT` (default `3000`).
16
+
17
+ ```bash
18
+ # Build
19
+ bun run build
20
+
21
+ # Start (OpenAPI)
22
+ PORT=3000 bun run start ./demo/simple/openapi.json
23
+
24
+ # Or with GraphQL schema
25
+ # PORT=3000 bun run start ./path/to/schema.graphql
26
+ ```
27
+
28
+ The server exposes:
29
+
30
+ - `POST /mcp` — bidirectional MCP endpoint
31
+ - `GET /mcp` and `DELETE /mcp` — session management via `StreamableHTTPServerTransport`
32
+
33
+ Pass a bearer token on the first `POST /mcp` initialize request to enable authenticated outgoing requests for generated tools:
34
+
35
+ ```
36
+ Authorization: Bearer <your-api-token>
37
+ ```
38
+
39
+ ### Inspector
40
+
41
+ You can attach the MCP Inspector to a running server instance:
42
+
43
+ ```bash
44
+ npx @modelcontextprotocol/inspector http://localhost:3000/mcp
45
+ ```
46
+
47
+ ### Demos
48
+
49
+ There is a small demo API under `demo/simple` and an accompanying OpenAPI document `demo/simple/openapi.json` you can use for local testing.
50
+
51
+ ```bash
52
+ # Run demo API (separate terminal)
53
+ PORT=5050 bun demo/simple/server.ts
54
+
55
+ # Start MCP server using demo OpenAPI
56
+ PORT=3000 bun run start ./demo/simple/openapi.json
57
+
58
+ # Open MCP Inspector
59
+ npx @modelcontextprotocol/inspector http://localhost:3000/mcp
60
+ ```
61
+
62
+ ### Programmatic
63
+
64
+ You can also import and run the server programmatically:
65
+
66
+ ```ts
67
+ import { MCPServer } from "@xyd-js/mcp-server";
68
+
69
+ const server = new MCPServer();
70
+ // Optionally pass Uniform source as argv[2] when starting the process
71
+ // or customize the class to set `uniformSource`.
72
+ ```
73
+
74
+ ## Endpoints and Behavior
75
+
76
+ - Stores a session-specific bearer token on initialization and uses it for tool requests
77
+ - Registers API reference resources and tools if `uniformSource` is provided
78
+ - Cleans up transports and tokens on session close
79
+
80
+ ## Scripts
81
+
82
+ Useful package scripts:
83
+
84
+ - `bun run build` — build to `dist/`
85
+ - `bun run dev` — watch `src/index.ts`
86
+ - `bun run start` — run compiled `dist/index.js`
87
+ - `bun run demo:simple` — watch demo API server (port 5050)
88
+ - `bun run mcp:inspector` — open MCP Inspector pointing at `http://localhost:3000/mcp`
89
+
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import('../dist/index.js');
3
+
4
+
@@ -0,0 +1,94 @@
1
+ import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
2
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
3
+
4
+ export class XydMcpClient {
5
+ private client: Client;
6
+ private transport: StreamableHTTPClientTransport;
7
+ private sessionId: string | null = null;
8
+
9
+ constructor(private serverUrl: string = "http://localhost:3000/mcp") {
10
+ this.transport = new StreamableHTTPClientTransport(new URL(this.serverUrl));
11
+ this.client = new Client(
12
+ {
13
+ name: "xyd-mcp-client",
14
+ version: "1.0.0",
15
+ },
16
+ {
17
+ capabilities: {
18
+ tools: {},
19
+ resources: {},
20
+ },
21
+ }
22
+ );
23
+ }
24
+
25
+ async connect(): Promise<void> {
26
+ try {
27
+ await this.client.connect(this.transport);
28
+ console.log("✅ Connected to MCP server");
29
+ } catch (error) {
30
+ console.error("❌ Failed to connect to MCP server:", error);
31
+ throw error;
32
+ }
33
+ }
34
+
35
+ async listTools(): Promise<any[]> {
36
+ try {
37
+ const response = await this.client.listTools();
38
+ console.log("🔧 Available tools:", response.tools);
39
+ return response.tools;
40
+ } catch (error) {
41
+ console.error("❌ Failed to list tools:", error);
42
+ throw error;
43
+ }
44
+ }
45
+
46
+ async listResources(): Promise<any[]> {
47
+ try {
48
+ const response = await this.client.listResources();
49
+ console.log("📚 Available resources:", response.resources);
50
+ return response.resources;
51
+ } catch (error) {
52
+ console.error("❌ Failed to list resources:", error);
53
+ throw error;
54
+ }
55
+ }
56
+
57
+ async callTool(name: string, args: any): Promise<any> {
58
+ try {
59
+ console.log(`🔧 Calling tool "${name}" with args:`, args);
60
+ const response = await this.client.callTool({ name, arguments: args });
61
+ console.log(`✅ Tool "${name}" response:`, response);
62
+ return response;
63
+ } catch (error) {
64
+ console.error(`❌ Failed to call tool "${name}":`, error);
65
+ throw error;
66
+ }
67
+ }
68
+
69
+ async readResource(uri: string): Promise<any> {
70
+ try {
71
+ console.log(`📖 Reading resource: ${uri}`);
72
+ const response = await this.client.readResource({ uri });
73
+ console.log(`✅ Resource content:`, response);
74
+ return response;
75
+ } catch (error) {
76
+ console.error(`❌ Failed to read resource "${uri}":`, error);
77
+ throw error;
78
+ }
79
+ }
80
+
81
+ async disconnect(): Promise<void> {
82
+ try {
83
+ await this.client.close();
84
+ console.log("🔌 Disconnected from MCP server");
85
+ } catch (error) {
86
+ console.error("❌ Failed to disconnect:", error);
87
+ throw error;
88
+ }
89
+ }
90
+
91
+ getSessionId(): string | undefined {
92
+ return this.transport.sessionId;
93
+ }
94
+ }