-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathserver.ts
More file actions
79 lines (69 loc) · 2.79 KB
/
Copy pathserver.ts
File metadata and controls
79 lines (69 loc) · 2.79 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
/**
* Posecode MCP server: exposes the Posecode protocol to any LLM agent.
*
* Three tools turn "an LLM knows biomechanics" into "an LLM can show movement":
* - posecode_authoring_guide: learn the .posecode language inline
* - validate_posecode: parse + surface configured range-of-motion clamps
* - render_posecode: get a playground link that animates the movement
*
* The server is decoupled from any transport so it can be driven over stdio in
* production and over an in-memory pair in tests.
*/
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
import { analyzePosecode, renderPosecode, DEFAULT_BASE_URL } from "./analyze.js";
import { authoringGuide } from "./guide.js";
export interface PosecodeServerOptions {
/** Base URL of the playground used for render permalinks. */
baseUrl?: string;
}
/** Package/server identity kept in sync by `version-packages`. */
export const POSECODE_MCP_VERSION = "0.5.0";
export function createPosecodeServer(opts: PosecodeServerOptions = {}): McpServer {
const baseUrl = opts.baseUrl ?? DEFAULT_BASE_URL;
const server = new McpServer({ name: "posecode", version: POSECODE_MCP_VERSION });
const sourceSchema = {
source: z.string().describe("The full .posecode document text"),
};
const asText = (value: unknown, isError = false) => ({
content: [{ type: "text" as const, text: JSON.stringify(value, null, 2) }],
isError,
});
server.registerTool(
"posecode_authoring_guide",
{
title: "How to write Posecode",
description:
"Return the guide that teaches the Posecode (.posecode) language: grammar, joints, actions, and an example. Read this before writing a movement.",
inputSchema: {},
},
async () => ({ content: [{ type: "text" as const, text: authoringGuide() }] }),
);
server.registerTool(
"validate_posecode",
{
title: "Validate a Posecode movement",
description:
"Parse a .posecode document and return any errors plus configured range-of-motion (ROM) clamps. Use this to check the source before showing it to a user; a clean result is not a clinical safety assessment.",
inputSchema: sourceSchema,
},
async ({ source }) => {
const result = analyzePosecode(source);
return asText(result, !result.ok);
},
);
server.registerTool(
"render_posecode",
{
title: "Render a Posecode movement to a link",
description:
"Validate a .posecode document and return a permalink that animates it as a 3D figure in the Posecode playground. Give the link to the user to view the movement.",
inputSchema: sourceSchema,
},
async ({ source }) => {
const result = renderPosecode(source, baseUrl);
return asText(result, !result.ok);
},
);
return server;
}