Canvas Components: - CustomExtractorNode.tsx: Node for custom Python extractors - CustomExtractorPanel.tsx: Configuration panel for custom extractors - ConnectionStatusIndicator.tsx: WebSocket status display - atomizer-spec.ts: TypeScript types for AtomizerSpec v2.0 Config: - migrator.py: Legacy config to AtomizerSpec v2.0 migration - Updated __init__.py exports for config and extractors MCP Tools: - spec.ts: MCP tools for spec manipulation - index.ts: Tool registration updates
130 lines
3.0 KiB
JavaScript
130 lines
3.0 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Atomizer MCP Server
|
|
*
|
|
* Provides tools for Claude to interact with Atomizer optimization workflows.
|
|
*
|
|
* Modes:
|
|
* - user: Safe operations (list, status, create, run, analyze)
|
|
* - power: Full access (edit files, create extractors, shell commands)
|
|
*/
|
|
|
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
import {
|
|
CallToolRequestSchema,
|
|
ListToolsRequestSchema,
|
|
} from "@modelcontextprotocol/sdk/types.js";
|
|
|
|
import { studyTools } from "./tools/study.js";
|
|
import { optimizationTools } from "./tools/optimization.js";
|
|
import { analysisTools } from "./tools/analysis.js";
|
|
import { reportingTools } from "./tools/reporting.js";
|
|
import { physicsTools } from "./tools/physics.js";
|
|
import { canvasTools } from "./tools/canvas.js";
|
|
import { specTools } from "./tools/spec.js";
|
|
import { adminTools } from "./tools/admin.js";
|
|
import { ATOMIZER_MODE } from "./utils/paths.js";
|
|
|
|
// Tool definition interface
|
|
export interface ToolDefinition {
|
|
name: string;
|
|
description: string;
|
|
inputSchema: {
|
|
type: "object";
|
|
properties?: Record<string, unknown>;
|
|
required?: string[];
|
|
};
|
|
}
|
|
|
|
export interface AtomizerTool {
|
|
definition: ToolDefinition;
|
|
handler: (args: Record<string, unknown>) => Promise<{
|
|
content: Array<{ type: string; text: string }>;
|
|
isError?: boolean;
|
|
}>;
|
|
}
|
|
|
|
// Collect all tools based on mode
|
|
const userTools: AtomizerTool[] = [
|
|
...studyTools,
|
|
...optimizationTools,
|
|
...analysisTools,
|
|
...reportingTools,
|
|
...physicsTools,
|
|
...canvasTools,
|
|
...specTools,
|
|
];
|
|
|
|
const powerTools: AtomizerTool[] = [
|
|
...userTools,
|
|
...adminTools,
|
|
];
|
|
|
|
const tools = ATOMIZER_MODE === "power" ? powerTools : userTools;
|
|
|
|
// Create server
|
|
const server = new Server(
|
|
{
|
|
name: "atomizer-tools",
|
|
version: "1.0.0",
|
|
},
|
|
{
|
|
capabilities: {
|
|
tools: {},
|
|
},
|
|
}
|
|
);
|
|
|
|
// Handle list tools request
|
|
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
return {
|
|
tools: tools.map((t) => t.definition),
|
|
};
|
|
});
|
|
|
|
// Handle tool calls
|
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
const { name, arguments: args } = request.params;
|
|
|
|
const tool = tools.find((t) => t.definition.name === name);
|
|
if (!tool) {
|
|
return {
|
|
content: [
|
|
{
|
|
type: "text",
|
|
text: `Unknown tool: ${name}`,
|
|
},
|
|
],
|
|
isError: true,
|
|
};
|
|
}
|
|
|
|
try {
|
|
return await tool.handler(args || {});
|
|
} catch (error) {
|
|
const message = error instanceof Error ? error.message : String(error);
|
|
return {
|
|
content: [
|
|
{
|
|
type: "text",
|
|
text: `Error executing ${name}: ${message}`,
|
|
},
|
|
],
|
|
isError: true,
|
|
};
|
|
}
|
|
});
|
|
|
|
// Start server
|
|
async function main() {
|
|
const transport = new StdioServerTransport();
|
|
await server.connect(transport);
|
|
console.error(`Atomizer MCP Server running in ${ATOMIZER_MODE} mode`);
|
|
}
|
|
|
|
main().catch((error) => {
|
|
console.error("Server error:", error);
|
|
process.exit(1);
|
|
});
|