-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.ts
More file actions
100 lines (86 loc) · 2.68 KB
/
Copy pathindex.ts
File metadata and controls
100 lines (86 loc) · 2.68 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
import { MCPServer } from "mcp-use";
import { z } from "zod";
const server = new MCPServer({
name: "resource-watcher",
title: "Resource Watcher",
version: "1.0.0",
description:
"Resource subscriptions and dynamic lists — showcasing live resource updates",
});
let config: Record<string, string> = {
theme: "light",
language: "en",
notifications: "on",
};
let featureFlags: Record<string, boolean> = {
darkMode: true,
betaFeatures: false,
};
server.resource(
{
name: "settings",
uri: "config://settings",
title: "Application Settings",
description: "Current application configuration",
mimeType: "application/json",
},
async (uri) => ({
contents: [{ uri: uri.href, mimeType: "application/json", text: JSON.stringify(config) }],
}),
);
const configOutputSchema = z.object({
config: z.record(z.string(), z.string()),
featureFlags: z.record(z.string(), z.boolean()),
});
export const showConfig = server.tool(
{
name: "show-config",
description:
"Display the configuration panel showing current settings and feature flags",
inputSchema: z.object({}),
outputSchema: configOutputSchema,
view: {
name: "config-panel",
description: "Configuration panel with live settings and feature flag toggles",
prefersBorder: true,
},
},
async () => {
const data = { config, featureFlags };
return { content: [{ type: "text", text: "Config loaded" }], structuredContent: data };
}
);
export const updateConfig = server.tool(
{
name: "update-config",
description: "Update a configuration setting by key and value",
inputSchema: z.object({
key: z.string().describe("Configuration key to update"),
value: z.string().describe("New value for the key"),
}),
outputSchema: configOutputSchema,
},
async ({ key, value }, ctx) => {
config[key] = value;
await server.notifyResourceUpdated("config://settings");
await ctx.sendNotification("custom/config-changed", { key, value });
const data = { config, featureFlags };
return { content: [{ type: "text", text: `Updated "${key}" to "${value}"` }], structuredContent: data };
}
);
export const toggleFeature = server.tool(
{
name: "toggle-feature",
description: "Toggle a feature flag on or off",
inputSchema: z.object({
feature: z.string().describe("Feature flag name"),
enabled: z.boolean().describe("Whether to enable the feature"),
}),
},
async ({ feature, enabled }) => {
featureFlags[feature] = enabled;
await server.notifyToolsChanged();
return { content: [{ type: "text", text: `Feature "${feature}" ${enabled ? "enabled" : "disabled"}` }] };
}
);
export default server;