Fixing eslint issues
Some checks failed
Main Workflow / Test and Build (20.x) (push) Successful in 3m58s
Main Workflow / Security Audit (push) Successful in 4m10s
Main Workflow / Test and Build (18.x) (push) Failing after 2m46s
Main Workflow / Build Release Artifacts (push) Has been skipped
Main Workflow / Code Quality Check (push) Failing after 1m51s
Main Workflow / Notification (push) Failing after 21s
Some checks failed
Main Workflow / Test and Build (20.x) (push) Successful in 3m58s
Main Workflow / Security Audit (push) Successful in 4m10s
Main Workflow / Test and Build (18.x) (push) Failing after 2m46s
Main Workflow / Build Release Artifacts (push) Has been skipped
Main Workflow / Code Quality Check (push) Failing after 1m51s
Main Workflow / Notification (push) Failing after 21s
This commit is contained in:
105
src/index.ts
105
src/index.ts
@ -11,7 +11,6 @@ import {
|
||||
ListToolsRequestSchema,
|
||||
McpError,
|
||||
ReadResourceRequestSchema,
|
||||
InitializeRequestSchema,
|
||||
} from '@modelcontextprotocol/sdk/types.js';
|
||||
|
||||
// Import tools and utilities
|
||||
@ -64,103 +63,103 @@ const createToolDefinitions = () => [
|
||||
properties: {
|
||||
name: {
|
||||
type: 'string',
|
||||
description: 'Name of the diagram file (without extension)'
|
||||
description: 'Name of the diagram file (without extension)',
|
||||
},
|
||||
type: {
|
||||
type: 'string',
|
||||
enum: Object.values(DiagramType),
|
||||
description: 'Type of diagram to create'
|
||||
description: 'Type of diagram to create',
|
||||
},
|
||||
format: {
|
||||
type: 'string',
|
||||
enum: Object.values(DiagramFormat),
|
||||
default: 'drawio',
|
||||
description: 'File format for the diagram'
|
||||
description: 'File format for the diagram',
|
||||
},
|
||||
description: {
|
||||
type: 'string',
|
||||
description: 'Natural language description of the diagram to generate using AI'
|
||||
description: 'Natural language description of the diagram to generate using AI',
|
||||
},
|
||||
outputPath: {
|
||||
type: 'string',
|
||||
description: 'Output directory path (relative to workspace)'
|
||||
description: 'Output directory path (relative to workspace)',
|
||||
},
|
||||
complexity: {
|
||||
type: 'string',
|
||||
enum: ['simple', 'detailed'],
|
||||
default: 'detailed',
|
||||
description: 'Complexity level of the generated diagram'
|
||||
description: 'Complexity level of the generated diagram',
|
||||
},
|
||||
language: {
|
||||
type: 'string',
|
||||
default: 'es',
|
||||
description: 'Language for diagram labels and text'
|
||||
description: 'Language for diagram labels and text',
|
||||
},
|
||||
// Legacy parameters for backward compatibility
|
||||
processName: {
|
||||
type: 'string',
|
||||
description: 'Name of the BPMN process (legacy)'
|
||||
description: 'Name of the BPMN process (legacy)',
|
||||
},
|
||||
tasks: {
|
||||
type: 'array',
|
||||
items: { type: 'string' },
|
||||
description: 'List of tasks for BPMN process (legacy)'
|
||||
description: 'List of tasks for BPMN process (legacy)',
|
||||
},
|
||||
gatewayType: {
|
||||
type: 'string',
|
||||
enum: ['exclusive', 'parallel'],
|
||||
description: 'Type of gateway for BPMN process (legacy)'
|
||||
description: 'Type of gateway for BPMN process (legacy)',
|
||||
},
|
||||
branches: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'array',
|
||||
items: { type: 'string' }
|
||||
items: { type: 'string' },
|
||||
},
|
||||
description: 'Branches for BPMN gateway (legacy)'
|
||||
description: 'Branches for BPMN gateway (legacy)',
|
||||
},
|
||||
beforeGateway: {
|
||||
type: 'array',
|
||||
items: { type: 'string' },
|
||||
description: 'Tasks before gateway (legacy)'
|
||||
description: 'Tasks before gateway (legacy)',
|
||||
},
|
||||
afterGateway: {
|
||||
type: 'array',
|
||||
items: { type: 'string' },
|
||||
description: 'Tasks after gateway (legacy)'
|
||||
description: 'Tasks after gateway (legacy)',
|
||||
},
|
||||
classes: {
|
||||
type: 'array',
|
||||
items: { type: 'string' },
|
||||
description: 'List of classes for UML class diagram (legacy)'
|
||||
description: 'List of classes for UML class diagram (legacy)',
|
||||
},
|
||||
entities: {
|
||||
type: 'array',
|
||||
items: { type: 'string' },
|
||||
description: 'List of entities for ER diagram (legacy)'
|
||||
description: 'List of entities for ER diagram (legacy)',
|
||||
},
|
||||
components: {
|
||||
type: 'array',
|
||||
items: { type: 'string' },
|
||||
description: 'List of components for network or architecture diagram (legacy)'
|
||||
description: 'List of components for network or architecture diagram (legacy)',
|
||||
},
|
||||
processes: {
|
||||
type: 'array',
|
||||
items: { type: 'string' },
|
||||
description: 'List of processes for flowchart (legacy)'
|
||||
}
|
||||
description: 'List of processes for flowchart (legacy)',
|
||||
},
|
||||
},
|
||||
required: ['name', 'type']
|
||||
}
|
||||
required: ['name', 'type'],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'get_diagram_types',
|
||||
description: 'Get list of supported diagram types with descriptions',
|
||||
inputSchema: {
|
||||
type: 'object',
|
||||
properties: {}
|
||||
}
|
||||
}
|
||||
properties: {},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// Pure function to create resource definitions
|
||||
@ -169,8 +168,8 @@ const createResourceDefinitions = () => [
|
||||
uri: 'diagrams://types/supported',
|
||||
name: 'Supported Diagram Types',
|
||||
mimeType: 'application/json',
|
||||
description: 'List of supported diagram types and their descriptions'
|
||||
}
|
||||
description: 'List of supported diagram types and their descriptions',
|
||||
},
|
||||
];
|
||||
|
||||
// Pure function to create tool handlers
|
||||
@ -179,22 +178,22 @@ const createToolHandlers = (config: ServerConfig): ToolHandlers => ({
|
||||
if (!validateCreateDiagramInput(args)) {
|
||||
throw new McpError(
|
||||
ErrorCode.InvalidParams,
|
||||
'Invalid create_diagram arguments'
|
||||
'Invalid create_diagram arguments',
|
||||
);
|
||||
}
|
||||
|
||||
const result = await createDiagram({
|
||||
...args,
|
||||
workspaceRoot: args.workspaceRoot || config.workspaceRoot
|
||||
workspaceRoot: args.workspaceRoot || config.workspaceRoot,
|
||||
});
|
||||
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: JSON.stringify(result, null, 2)
|
||||
}
|
||||
]
|
||||
text: JSON.stringify(result, null, 2),
|
||||
},
|
||||
],
|
||||
};
|
||||
},
|
||||
|
||||
@ -202,7 +201,7 @@ const createToolHandlers = (config: ServerConfig): ToolHandlers => ({
|
||||
const types = getSupportedDiagramTypes();
|
||||
const typesWithDescriptions = types.map(type => ({
|
||||
type,
|
||||
description: getDiagramTypeDescription(type)
|
||||
description: getDiagramTypeDescription(type),
|
||||
}));
|
||||
|
||||
return {
|
||||
@ -211,21 +210,21 @@ const createToolHandlers = (config: ServerConfig): ToolHandlers => ({
|
||||
type: 'text',
|
||||
text: JSON.stringify({
|
||||
success: true,
|
||||
supportedTypes: typesWithDescriptions
|
||||
}, null, 2)
|
||||
}
|
||||
]
|
||||
supportedTypes: typesWithDescriptions,
|
||||
}, null, 2),
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
// Pure function to create resource handlers
|
||||
const createResourceHandlers = (config: ServerConfig): ResourceHandlers => ({
|
||||
const createResourceHandlers = (_config: ServerConfig): ResourceHandlers => ({
|
||||
'diagrams://types/supported': async () => {
|
||||
const types = getSupportedDiagramTypes();
|
||||
const typesWithDescriptions = types.map(type => ({
|
||||
type,
|
||||
description: getDiagramTypeDescription(type)
|
||||
description: getDiagramTypeDescription(type),
|
||||
}));
|
||||
|
||||
return {
|
||||
@ -233,18 +232,18 @@ const createResourceHandlers = (config: ServerConfig): ResourceHandlers => ({
|
||||
{
|
||||
uri: 'diagrams://types/supported',
|
||||
mimeType: 'application/json',
|
||||
text: JSON.stringify(typesWithDescriptions, null, 2)
|
||||
}
|
||||
]
|
||||
text: JSON.stringify(typesWithDescriptions, null, 2),
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
// Pure function to setup tool request handlers
|
||||
const setupToolRequestHandlers = (server: Server, toolHandlers: ToolHandlers) => {
|
||||
// List available tools
|
||||
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
||||
tools: createToolDefinitions()
|
||||
tools: createToolDefinitions(),
|
||||
}));
|
||||
|
||||
// Handle tool calls
|
||||
@ -254,7 +253,7 @@ const setupToolRequestHandlers = (server: Server, toolHandlers: ToolHandlers) =>
|
||||
if (!handler) {
|
||||
throw new McpError(
|
||||
ErrorCode.MethodNotFound,
|
||||
`Unknown tool: ${request.params.name}`
|
||||
`Unknown tool: ${request.params.name}`,
|
||||
);
|
||||
}
|
||||
|
||||
@ -280,7 +279,7 @@ const setupToolRequestHandlers = (server: Server, toolHandlers: ToolHandlers) =>
|
||||
const setupResourceRequestHandlers = (server: Server, resourceHandlers: ResourceHandlers) => {
|
||||
// List available resources
|
||||
server.setRequestHandler(ListResourcesRequestSchema, async () => ({
|
||||
resources: createResourceDefinitions()
|
||||
resources: createResourceDefinitions(),
|
||||
}));
|
||||
|
||||
// Handle resource requests
|
||||
@ -292,7 +291,7 @@ const setupResourceRequestHandlers = (server: Server, resourceHandlers: Resource
|
||||
if (!handler) {
|
||||
throw new McpError(
|
||||
ErrorCode.InvalidRequest,
|
||||
`Unknown resource URI: ${uri}`
|
||||
`Unknown resource URI: ${uri}`,
|
||||
);
|
||||
}
|
||||
|
||||
@ -300,7 +299,7 @@ const setupResourceRequestHandlers = (server: Server, resourceHandlers: Resource
|
||||
} catch (error) {
|
||||
throw new McpError(
|
||||
ErrorCode.InternalError,
|
||||
`Failed to read resource: ${error}`
|
||||
`Failed to read resource: ${error}`,
|
||||
);
|
||||
}
|
||||
});
|
||||
@ -323,7 +322,7 @@ const createMCPServer = (config: ServerConfig): Server => {
|
||||
},
|
||||
{
|
||||
capabilities: config.capabilities,
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
const toolHandlers = createToolHandlers(config);
|
||||
@ -368,7 +367,7 @@ const isInitializeRequest = (body: any): boolean => {
|
||||
};
|
||||
|
||||
// Pure function to create session transport
|
||||
const createSessionTransport = (config: ServerConfig): StreamableHTTPServerTransport => {
|
||||
const createSessionTransport = (_config: ServerConfig): StreamableHTTPServerTransport => {
|
||||
return new StreamableHTTPServerTransport({
|
||||
sessionIdGenerator: () => randomUUID(),
|
||||
onsessioninitialized: (sessionId) => {
|
||||
@ -484,8 +483,8 @@ const setupAPIRoutes = (app: express.Application, config: ServerConfig) => {
|
||||
services: {
|
||||
mcp: 'operational',
|
||||
diagramGeneration: 'operational',
|
||||
sessions: Object.keys(transports).length
|
||||
}
|
||||
sessions: Object.keys(transports).length,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user