Skip to content

Commit 1e459cc

Browse files
committed
Fix some module issues and updated Readme
1 parent cbec4c1 commit 1e459cc

File tree

11 files changed

+163
-72
lines changed

11 files changed

+163
-72
lines changed

README.md

Lines changed: 31 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,87 @@
11
# MCP-OpenAPI Model Context Protocol wrapper for OpenAPI compliant endpoints
2+
This is a Proof-of-Concept project implementing a multi-purpose OpenAPI MCP Server that can be used to proxy any OpenAPI compliant API backend with an MCP Server protocol
23

3-
The main application mcp-openapi provides a generic MCP Server wrapper over any OpenAPI compliant endpoints. It will, given the OpenAPI specs, generate MCP tools & resources with some sensible defaults and overridable via configuration. It will also allow definition of additional MCP Prompts, via config. It will hosts the MCP end points for all these MCP capabilities and integrate with the backend APIs as per the configuration.
4+
The project also comes with an example OpenAPI application hosting some sample banking APIs with some manufactured data, a demo MCP Client application that provides an example use-case of an MCP Client interacting with the MCP Server proxying some sample problems between the sample banking APIs and an LLM (hosting via LMStudio).
45

5-
This project provides comprehensive set of apps demonstrating how to use the mcp-openapi MCP Server over existing APIs via the sample banking api app.
6+
Demo/Testing can also be done without the demo MCP application or LM Studio via integrating the MCP server with an MCP enabled tools such as Cursor IDE (tested) or Windsurf (not tested), etc.
67

7-
The mcp-test-client is an example MCP client taking in some pre-baked prompts containing some common, but manufactured, banking scenarios and connecting & orchestrating between the scenarios, the MCP server fronting the sample banking APIs and an LLM.
8+
All the above are structured under 3 separate folders under this project:
89

9-
The sample-banking-api and mcp-test-client app are not expected to be re-used and is for demo purposes only.
10+
1. **mcp-openapi** is the reference implementation of the OpenAPI MCP proxy
11+
2. **mcp-test-client** is the demo test client with some sample questions based on the manufactured data in the sample banking app
12+
3. **sample-banking-api** is the sample banking application with a number of OpenAPI endpoints and manufactured data
1013

1114
NOTE: This mcp-openapi app is not a replacement for https://github.com/ReAPI-com/mcp-openapi project that is enabling IDEs like Cursor to connect to open api specs to support api development.
1215

1316
## 🔄 Integration Flow
1417

1518
```
16-
Sample Banking API ←→ MCP OpenAPI Server ←→ Demo/Test Banking MCP Client ←→ LLM/AI Application
19+
Sample Banking API ←→ MCP OpenAPI Server ←→ Demo/Test Banking MCP Client ←→ LLM via LM Studio
1720
```
21+
or
1822

19-
1. **Sample Banking API** provides some RESTful banking services with authentication
20-
2. **MCP OpenAPI Server** wraps the API as MCP tools and resources
21-
3. **Test/Demo MCP Client** consumes the MCP server for AI integration
22-
4. **LLM/AI Application** uses the tools through the MCP protocol - for the demo/test we have implemented LM Studio integration
23+
```
24+
Sample Banking API ←→ MCP OpenAPI Server ←→ Cursor IDE
25+
```
2326

2427

2528
## 🏗️ Project Structure
2629

2730
This repository contains three applications:
2831

2932
### 🔌 [`mcp-openapi/`](./mcp-openapi/)
30-
This contain the main application, a **generic, configurable MCP server** that automatically generates MCP tools and resources from OpenAPI specifications:
33+
This contain the main application, a **multi-purpose, configurable MCP server** that automatically generates MCP tools and resources from OpenAPI specifications:
3134
- Automatic tool/resource generation from OpenAPI specs
3235
- Token passthrough authentication
33-
- Custom prompt templates
36+
- Addition of custom prompt templates
3437
- Multiple deployment modes (stdio/HTTP)
35-
- Comprehensive test coverage (61/61 tests passing)
3638

3739
**Quick Start:**
3840
```bash
3941
cd mcp-openapi
4042
npm install
41-
npm run dev -- --specs ./examples/specs --config ./examples/mcp-config.json --verbose
43+
npm run build
44+
npm run dev
4245
```
4346

47+
The "dev" startup is pre-configured to integrate with the sample banking api app. Please refer to the README in the app folder for more details.
4448

4549
### 📊 [`sample-banking-api/`](./sample-banking-api/)
4650
An example **Sample banking API implementation** with:
4751
- RESTful endpoints for payments, payees, and products
4852
- basic JWT authentication and validation
4953
- OpenAPI specifications
50-
- Comprehensive test suite
5154
- Manufactured data, via JSON files, to support the app
5255
- Purpose of this is to support the demo and usage of the main application
5356

5457
**Quick Start:**
5558
```bash
5659
cd sample-banking-api
5760
npm install
58-
npm run server:dev
61+
npm start
5962
```
6063

61-
### 🧪 [`mcp-test-client/`](./mcp-test-client/)
62-
An example **test client application, including an MCP Client** for validating MCP server functionality over the sample banking app. The sample client app will also integrate with an LLM, LM Studio integration provided, to demo the MCP flow.
64+
Please refer to the README in the app folder for more details.
6365

66+
### 🧪 [`mcp-test-client/`](./mcp-test-client/)
67+
A **Demo MCP client application** for validating MCP server functionality over the sample banking app. The sample client app will also integrate with an LLM, via a local LM Studio integration, to demo the MCP flow.
6468

65-
## 🚀 Getting Started
69+
This requires LM Studio to be running locally on default port 1234 (i.e. http://localhost:1234), but configurable if it is running on different port. LM Studio must be loaded with an LLM that supports tool calling (tested on meta-llama-3.1-8b-instruct model).
6670

67-
### 1. Start the Banking API
68-
```bash
69-
cd sample-banking-api
70-
npm install
71-
npm run server:dev
72-
# Server runs on http://localhost:3001
73-
```
74-
75-
### 2. Start the MCP Server
71+
**Quick Start:**
7672
```bash
77-
cd mcp-openapi
73+
cd mcp-test-client
7874
npm install
79-
npm run dev -- --specs ./examples/specs --config ./examples/mcp-config.json --verbose
80-
# MCP server runs on http://localhost:4000 and will connect to banking API to serve requests
75+
npm start
8176
```
77+
This will launch the demo mcp client which is a CLI menu driven app with a few pre-configured test scenarios against the manufactured data in the sample banking app.
8278

83-
### 3. Start/Load you LLM in LM Studio
84-
Load and start your LLM in LM Studio. This project assumes the LM Studio API will be running on http://localhost:1234
85-
86-
If you need to change the URL, update the /examples/mcp-config.json file in the mcp-openapi app and restart it.
87-
88-
### 4. Testing or running the demo
89-
Once you've started all the different moving parts to test/demo. Refer to the mcp-client-test Readme to launch the demo/client. It is menu driven with a number of pre-build test scenarios using the manufactured data in the sample banking api app.
79+
Please refer to the README in the app folder for more details.
9080

9181
## 📋 Features
9282

93-
### Banking API Features
94-
-Complete CRUD operations for payments, payees, products
83+
### Sample Banking API Features
84+
-Sample data with APIs for payments, payees, products
9585
- ✅ JWT authentication with bearer tokens
9686
- ✅ OpenAPI 3.0 specifications
9787
- ✅ Request validation and error handling
@@ -135,11 +125,8 @@ npm test
135125
## 🎯 Use Cases
136126

137127
This project demonstrates:
138-
- **API Wrapping**: How to wrap existing REST APIs as MCP servers
139-
- **Authentication Patterns**: Token passthrough for secure API access
140-
- **Error Handling**: Production-ready error handling with security monitoring
141-
- **Testing Strategies**: Comprehensive test coverage for API wrappers
142-
- **Development Workflow**: Local development with hot reloading
128+
- **Multi-purpose API Wrapping**: How to wrap existing REST APIs with an MCP server
129+
- **MCP Prompts augmentation**: Adding custom MCP prompts to enable higher order/composite usage of those API via MCP
143130

144131
## 🤝 Contributing
145132

mcp-test-client/src/llm-interface.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { MCPCapabilities } from './types.js';
22

3-
export { MCPCapabilities };
4-
53
/**
64
* Generic LLM Interface - works with any LLM implementation
75
* This keeps the orchestrator clean and swappable

mcp-test-client/tests/setup.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Jest setup file for global test configuration
3+
*/
4+
export declare const mockConsole: {
5+
log: jest.SpyInstance<void, [message?: any, ...optionalParams: any[]], any>;
6+
info: jest.SpyInstance<void, [message?: any, ...optionalParams: any[]], any>;
7+
warn: jest.SpyInstance<void, [message?: any, ...optionalParams: any[]], any>;
8+
error: jest.SpyInstance<void, [message?: any, ...optionalParams: any[]], any>;
9+
};
10+
export declare const restoreConsole: () => void;
11+
//# sourceMappingURL=setup.d.ts.map

mcp-test-client/tests/setup.d.ts.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mcp-test-client/tests/setup.js

Lines changed: 82 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mcp-test-client/tests/setup.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mcp-test-client/tsconfig.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
"target": "ES2022",
44
"module": "ESNext",
55
"moduleResolution": "node",
6-
"allowSyntheticDefaultImports": true,
7-
"esModuleInterop": true,
8-
"allowJs": true,
9-
"sourceMap": true,
6+
"lib": ["ES2022"],
107
"outDir": "./dist",
8+
119
"strict": true,
12-
"declaration": true,
10+
"esModuleInterop": true,
1311
"skipLibCheck": true,
1412
"forceConsistentCasingInFileNames": true,
13+
"declaration": true,
14+
"declarationMap": true,
15+
"sourceMap": true,
16+
"removeComments": false,
17+
"allowSyntheticDefaultImports": true,
1518
"resolveJsonModule": true,
1619
"types": ["jest", "node"]
1720
},
@@ -21,6 +24,7 @@
2124
],
2225
"exclude": [
2326
"node_modules",
24-
"dist"
27+
"dist",
28+
"**/*.test.ts"
2529
]
2630
}

sample-banking-api/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
"name": "banking-api-server",
33
"version": "1.0.0",
44
"description": "Express.js server for Banking Payee Management API",
5-
"main": "index.js",
5+
"main": "dist/index.js",
6+
"type": "module",
67
"scripts": {
78
"build": "tsc",
8-
"server": "ts-node server/server.ts",
9-
"server:dev": "nodemon server/server.ts",
9+
"server": "tsx server/server.ts",
10+
"server:dev": "nodemon --exec \"tsx\" server/server.ts",
1011
"server:build": "tsc server/server.ts --outDir dist",
1112
"server:start": "node dist/server.js",
1213
"start": "npm run server",
@@ -15,7 +16,7 @@
1516
"test:watch": "jest --watch",
1617
"test:coverage": "jest --coverage",
1718
"test:ci": "jest --ci --coverage --watchAll=false",
18-
"test:server": "ts-node test-server.ts",
19+
"test:server": "tsx test-server.ts",
1920
"test:curl": "curl -X POST http://localhost:3001/auth/generate-token"
2021
},
2122
"keywords": [

sample-banking-api/server/server.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ import jwt from 'jsonwebtoken';
77
import { validationResult } from 'express-validator';
88
import fs from 'fs';
99
import path from 'path';
10-
import payeeRoutes, { setPayeesDataReference, setSavePayeesDataFunction } from './routes/payeeRoutes';
11-
import paymentRoutes, { setPaymentsDataReference, setSavePaymentsDataFunction, setPayeesDataReference as setPayeesDataReferenceForPayments } from './routes/paymentRoutes';
12-
import productRoutes, { setProductsDataReference } from './routes/productRoutes';
10+
import { fileURLToPath } from 'url';
11+
12+
const __filename = fileURLToPath(import.meta.url);
13+
const __dirname = path.dirname(__filename);
14+
import payeeRoutes, { setPayeesDataReference, setSavePayeesDataFunction } from './routes/payeeRoutes.js';
15+
import paymentRoutes, { setPaymentsDataReference, setSavePaymentsDataFunction, setPayeesDataReference as setPayeesDataReferenceForPayments } from './routes/paymentRoutes.js';
16+
import productRoutes, { setProductsDataReference } from './routes/productRoutes.js';
1317
import swaggerUi from 'swagger-ui-express';
1418
import YAML from 'yamljs';
1519

@@ -379,6 +383,6 @@ process.on('SIGINT', () => {
379383
export default app;
380384

381385
// Start the server if this file is run directly
382-
if (require.main === module) {
386+
if (import.meta.url === `file://${process.argv[1]}`) {
383387
startServer();
384388
}

sample-banking-api/test-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,6 @@ async function runAllTests() {
421421
export { testBankingServer, testServerWithoutAuth, runAllTests };
422422

423423
// Run tests if this file is executed directly
424-
if (require.main === module) {
424+
if (import.meta.url === `file://${process.argv[1]}`) {
425425
runAllTests().catch(console.error);
426426
}

0 commit comments

Comments
 (0)