-
Notifications
You must be signed in to change notification settings - Fork 191
Expand file tree
/
Copy pathserver.ts
More file actions
110 lines (102 loc) · 2.89 KB
/
Copy pathserver.ts
File metadata and controls
110 lines (102 loc) · 2.89 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
import { McpServer, ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
import * as z from "zod";
import { listSkills, loadSkill } from "./skills.js";
import { assembleDocument } from "./renderer.js";
export function createMcpServer(): McpServer {
const server = new McpServer({
name: "open-generative-ui",
version: "0.1.0",
});
// Resources: list and get skills
server.registerResource(
"skills-list",
"skills://list",
{ description: "JSON array of available skill names", mimeType: "application/json" },
async () => ({
contents: [
{
uri: "skills://list",
mimeType: "application/json",
text: JSON.stringify(listSkills()),
},
],
})
);
server.registerResource(
"skill",
new ResourceTemplate("skills://{name}", {
list: async () => ({
resources: listSkills().map((name) => ({
uri: `skills://${name}`,
name,
mimeType: "text/plain",
})),
}),
}),
{ description: "Full text of a skill instruction document", mimeType: "text/plain" },
async (uri, { name }) => ({
contents: [
{
uri: uri.href,
mimeType: "text/plain",
text: loadSkill(name as string),
},
],
})
);
// Prompts: pre-composed skill prompts
server.registerPrompt(
"create_widget",
{ description: "Instructions for creating interactive HTML widgets" },
async () => ({
messages: [
{
role: "user",
content: { type: "text", text: loadSkill("master-agent-playbook") },
},
],
})
);
server.registerPrompt(
"create_svg_diagram",
{ description: "Instructions for creating inline SVG diagrams" },
async () => ({
messages: [
{
role: "user",
content: { type: "text", text: loadSkill("svg-diagram-skill") },
},
],
})
);
server.registerPrompt(
"create_visualization",
{ description: "Advanced visualization instructions" },
async () => ({
messages: [
{
role: "user",
content: { type: "text", text: loadSkill("agent-skills-vol2") },
},
],
})
);
// Tool: assemble complete HTML document with design system
server.registerTool(
"assemble_document",
{
description:
"Wraps HTML with OpenGenerativeUI theme CSS, SVG classes, form styles, and bridge JS. " +
"Returns a complete iframe-ready HTML document.",
inputSchema: {
title: z.string().describe("Short title for the visualization"),
description: z.string().describe("One-sentence explanation of what this shows"),
html: z.string().describe("Self-contained HTML fragment with inline <style> and <script>"),
},
},
async ({ html }) => ({
content: [{ type: "text", text: assembleDocument(html) }],
})
);
return server;
}