UNPKG

@kpritam/gremlin-mcp

Version:

A Gremlin MCP server that allows for fetching status, schema, and querying using Gremlin for any Gremlin-compatible graph database (TypeScript implementation).

62 lines 2.22 kB
/** * MCP Resource handlers for Gremlin server. */ import { RESOURCE_URIS, MIME_TYPES } from '../constants.js'; import { logger } from '../logger.js'; /** * Register resource handlers with the MCP server. * * @param server - The MCP server instance * @param getGraphClient - Function to get the Gremlin client instance */ export function registerResourceHandlers(server, getGraphClient) { // Register graph status resource server.registerResource('graph-status', RESOURCE_URIS.STATUS, { title: 'Graph Status', description: 'Get the status of the currently configured Gremlin graph', mimeType: MIME_TYPES.TEXT_PLAIN, }, async (uri) => { try { const graphClient = await getGraphClient(); const status = await graphClient.getStatus(); return { contents: [ { uri: uri.href, mimeType: MIME_TYPES.TEXT_PLAIN, text: status, }, ], }; } catch (error) { logger.error('Error reading graph status resource', { uri: uri.href, error }); throw error; } }); // Register graph schema resource server.registerResource('graph-schema', RESOURCE_URIS.SCHEMA, { title: 'Graph Schema', description: 'Get the schema for the graph including the vertex and edge labels as well as the (vertex)-[edge]->(vertex) combinations', mimeType: MIME_TYPES.APPLICATION_JSON, }, async (uri) => { try { const graphClient = await getGraphClient(); const schema = await graphClient.getSchema(); return { contents: [ { uri: uri.href, mimeType: MIME_TYPES.APPLICATION_JSON, text: JSON.stringify(schema, null, 2), }, ], }; } catch (error) { logger.error('Error reading graph schema resource', { uri: uri.href, error }); throw error; } }); } //# sourceMappingURL=resources.js.map