-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpress-example.ts
More file actions
45 lines (38 loc) · 1.19 KB
/
express-example.ts
File metadata and controls
45 lines (38 loc) · 1.19 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
/**
* Example: Using doc-mcp with Express
*
* Run: npx ts-node examples/express-example.ts
*/
import express from 'express';
import docmcp from '../src';
async function main() {
const app = express();
// Initialize doc-mcp with OpenAPI documentation
const mcp = await docmcp(app, {
docs: './examples/petstore.yaml',
basePath: '/mcp',
verbose: true,
metadata: {
title: 'Pet Store API',
description: 'A sample pet store API with MCP endpoints',
},
});
// Add a simple health check
app.get('/health', (req, res) => {
res.json({ status: 'ok' });
});
// Access schema programmatically
const schema = mcp.getSchema();
console.log(`Loaded ${schema.endpoints.length} endpoints`);
// Start server
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
console.log(`\nMCP endpoints:`);
console.log(` GET http://localhost:${PORT}/mcp/describe`);
console.log(` GET http://localhost:${PORT}/mcp/schemas`);
console.log(` GET http://localhost:${PORT}/mcp/endpoints`);
console.log(` GET http://localhost:${PORT}/mcp/auth`);
});
}
main().catch(console.error);