-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmcp-stellar-xdr.ts
More file actions
executable file
·113 lines (102 loc) · 2.6 KB
/
mcp-stellar-xdr.ts
File metadata and controls
executable file
·113 lines (102 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env -S deno run --allow-read
import { McpServer } from "npm:@modelcontextprotocol/sdk@1.17.5/server/mcp.js";
import { StdioServerTransport } from "npm:@modelcontextprotocol/sdk@1.17.5/server/stdio.js";
import { z } from "npm:zod@3.25.76";
import init, {
decode,
encode,
guess,
schema,
types,
} from "npm:@stellar/stellar-xdr-json@23.0.0";
await init();
const server = new McpServer({
name: "mcp-stellar-xdr",
version: "0.1.0",
});
// Register the types tool
server.registerTool(
"types",
{
title: "Get Supported XDR Types",
description: "Get the list of supported XDR types.",
inputSchema: {},
},
() => {
const list = types();
return { content: [{ type: "text", text: `${JSON.stringify(list)}` }] };
},
);
// Register the json_schema tool
server.registerTool(
"json_schema",
{
title: "Get JSON Schema for XDR Type",
description: "Get the JSON schema for a specific XDR type.",
inputSchema: {
type: z.string().describe("XDR type"),
},
},
({ type }) => {
const json_schema = schema(type);
return { content: [{ type: "text", text: `${json_schema}` }] };
},
);
// Register the guess tool
server.registerTool(
"guess",
{
title: "Guess XDR Type",
description:
"Guess what type Stellar XDR is, getting back a list of possible types.",
inputSchema: {
xdr: z.string().describe("Base64 encoded XDR"),
},
},
({ xdr }) => {
const list = guess(xdr);
return { content: [{ type: "text", text: `${JSON.stringify(list)}` }] };
},
);
// Register the decode tool
server.registerTool(
"decode",
{
title: "Decode XDR to JSON",
description:
"Decode a Stellar XDR to JSON, given a type name and Base64 XDR.",
inputSchema: {
type: z.string().describe("XDR type"),
xdr: z.string().describe("Base64 encoded XDR"),
},
},
({ type, xdr }) => {
const json = decode(type, xdr);
return { content: [{ type: "text", text: `${json}` }] };
},
);
// Register the encode tool
server.registerTool(
"encode",
{
title: "Encode JSON to XDR",
description: "Encode a Stellar XDR from JSON.",
inputSchema: {
type: z.string().describe("XDR type"),
json: z.string().describe("JSON adhering to the types JSON Schema"),
},
},
({ type, json }) => {
const xdr = encode(type, json);
return { content: [{ type: "text", text: `${xdr}` }] };
},
);
async function main() {
const transport = new StdioServerTransport();
await server.connect(transport);
}
main().catch((error) => {
console.error("Server error:", error);
Deno.exit(1);
});
export { server };