mcp-chain-of-draft-server
Version:
A Model Context Protocol server which provides Chain of Draft style thinking
77 lines (76 loc) • 2.07 kB
JavaScript
import swaggerJSDoc from 'swagger-jsdoc';
import swaggerUi from 'swagger-ui-express';
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
// Get current file directory in ES module context
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
/**
* Read the package.json file to get the version number
*/
const packageJsonPath = path.join(__dirname, '../../package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
/**
* Swagger definition
*/
const swaggerDefinition = {
openapi: '3.0.0',
info: {
title: 'Memento MCP Server API',
version: packageJson.version,
description: 'API documentation for the Memento MCP Server',
license: {
name: 'MIT',
url: 'https://opensource.org/licenses/MIT',
},
contact: {
name: 'API Support',
email: 'support@example.com',
},
},
servers: [
{
url: '/api',
description: 'API server',
},
],
tags: [
{
name: 'Content',
description: 'Content management and operations',
},
{
name: 'Tags',
description: 'Tag management and operations',
},
{
name: 'Spaces',
description: 'Space management and operations',
},
],
};
/**
* Options for the swagger docs
*/
const options = {
swaggerDefinition,
// Paths to files containing OpenAPI definitions
apis: ['./src/web/routes/*.ts', './src/utils/swaggerSchemas.ts'],
};
/**
* Swagger specification
*/
const swaggerSpec = swaggerJSDoc(options);
/**
* Function to setup Swagger UI
*/
export const setupSwagger = (app) => {
// Swagger page
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
// Docs in JSON format
app.get('/api-docs.json', (req, res) => {
res.setHeader('Content-Type', 'application/json');
res.send(swaggerSpec);
});
};