Skip to content

Commit 163321b

Browse files
committed
Added stdio support and tested with Cursor
1 parent e1f6bef commit 163321b

File tree

8 files changed

+602
-150
lines changed

8 files changed

+602
-150
lines changed

.talismanrc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
fileignoreconfig:
22
- filename: mcp-openapi/examples/prompts/loan-recommendation.json
33
checksum: 09d2510be300d41bae68e4d2844bb8ff801c9ce792ad7e71404d865865ca6e9b
4-
version: "1.0"
4+
version: "1.0"
5+
6+
fileignoreconfig:
7+
- filename: mcp-openapi/src/server.ts
8+
checksum: 9d67e50aa65f1d3de3d39b290725d903bb92c72137057ec2424c92563acb59aa

mcp-openapi/README.md

Lines changed: 94 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,37 @@ mcp-openapi-server --specs ./my-specs --config ./my-config.json --prompts ./my-p
6262
# Override the backend API base URL (takes precedence over config file)
6363
mcp-openapi-server --base-url https://api.example.com --specs ./specs --verbose
6464

65-
# For different environments
65+
# For different environments (stdio mode)
6666
mcp-openapi-server --base-url http://localhost:8080 --specs ./specs # Development
6767
mcp-openapi-server --base-url https://staging-api.com --specs ./specs # Staging
6868
mcp-openapi-server --base-url https://api.production.com --specs ./specs # Production
69+
70+
# For HTTP mode deployments
71+
mcp-openapi-server --http --base-url https://api.example.com --specs ./specs --port 4000
72+
```
73+
74+
## 🔧 Mode Selection Guide
75+
76+
**When to use Stdio Mode (Default):**
77+
- ✅ IDE integration (Cursor, Claude Desktop, VS Code with MCP extensions)
78+
- ✅ Production MCP server deployment
79+
- ✅ Direct MCP client connections
80+
- ✅ Microservices with MCP protocol
81+
82+
**When to use HTTP Mode (`--http` flag):**
83+
- ✅ Web application integration
84+
- ✅ Development and testing with HTTP clients
85+
- ✅ Health checks and monitoring endpoints
86+
- ✅ Docker deployments with port mapping
87+
- ✅ Load balancing and reverse proxy setups
88+
89+
**Quick Mode Selection:**
90+
```bash
91+
# For IDEs and MCP clients (recommended)
92+
mcp-openapi-server
93+
94+
# For web APIs and testing
95+
mcp-openapi-server --http
6996
```
7097

7198
## Development Mode
@@ -80,17 +107,29 @@ npm install
80107

81108
### Development Commands
82109

83-
**Development Mode with Hot Reload (Recommended), will use the examples folder containing banking examples:**
110+
**Development Mode with Hot Reload (HTTP mode - Recommended for testing):**
84111
```bash
85112
npm run dev
86113
```
87114

88-
**HTTP Mode for Testing:**
115+
**Development Mode (Stdio mode for MCP integration testing):**
89116
```bash
117+
npm run dev:stdio
118+
```
119+
120+
**Production HTTP Mode:**
121+
```bash
122+
npm run build
90123
npm run start:http
91124
```
92125

93-
**Build and Run:**
126+
**Production Stdio Mode (MCP Integration):**
127+
```bash
128+
npm run build
129+
npm run start:stdio
130+
```
131+
132+
**Legacy Start Command (HTTP mode):**
94133
```bash
95134
npm run build
96135
npm start
@@ -103,14 +142,14 @@ npm run sast
103142

104143
### Development Environment Setup
105144

106-
**For stdio Mode (IDE Integration):**
145+
**For Stdio Mode (IDE Integration):**
107146
```bash
108147
# Set environment variables for authentication
109148
export BANKING_API_TOKEN="your-service-token-here"
110149
export USER_API_TOKEN="your-user-token-here"
111150

112-
# Run with verbose logging
113-
npm run dev -- --verbose
151+
# Run in stdio mode for MCP testing
152+
npm run dev:stdio
114153
```
115154

116155
**For HTTP Mode (API Testing):**
@@ -126,20 +165,42 @@ curl http://localhost:4000/info
126165
```
127166

128167
### Expected Output
129-
When running in development mode, you should see:
168+
169+
**HTTP Mode (`npm run dev` or `--http` flag):**
130170
```
131171
🚀 MCP OpenAPI Server running on port 4000
132172
📊 Health check: http://localhost:4000/health
133173
ℹ️ Server info: http://localhost:4000/info
134-
📋 Loaded 3 specs, 6 tools, 3 resources, 2 prompts
174+
📋 Loaded 3 specs, 4 tools, 5 resources, 2 prompts
175+
```
176+
177+
**Stdio Mode (`npm run dev:stdio` or default CLI):**
178+
```
179+
🔌 MCP OpenAPI Server running on stdio
180+
🌐 Using base URL: http://localhost:3001 (from config file)
181+
✅ Loaded 3 specs, 4 tools, 5 resources, 2 prompts
135182
```
136183

184+
### Available npm Scripts
185+
186+
| Script | Mode | Purpose |
187+
|--------|------|---------|
188+
| `npm run dev` | **HTTP** | Development with hot reload and web interface |
189+
| `npm run dev:stdio` | **Stdio** | Development for MCP integration testing |
190+
| `npm run start` | **HTTP** | Production HTTP server (legacy) |
191+
| `npm run start:stdio` | **Stdio** | Production MCP server (stdio mode) |
192+
| `npm run start:http` | **HTTP** | Production HTTP server (explicit) |
193+
| `npm run build` | - | Build TypeScript to JavaScript |
194+
| `npm run test` | - | Run all tests |
195+
137196
### Development Tips
138197

139198
- **Hot Reload**: The `npm run dev` command uses `tsx` for automatic TypeScript compilation and hot reloading
140-
- **Verbose Logging**: Add `--verbose` flag to see detailed debug information
199+
- **MCP Testing**: Use `npm run dev:stdio` to test MCP integration locally
200+
- **Verbose Logging**: Enabled by default, add `--verbose=false` to disable
141201
- **Banking Examples**: Use the pre-configured banking examples in `./examples/` for testing
142202
- **Authentication Testing**: Set environment variables for token passthrough testing
203+
- **Mode Selection**: Choose stdio for IDE integration, HTTP for web APIs
143204

144205
## Usage Modes
145206

@@ -157,23 +218,29 @@ Run as an independent server process, perfect for:
157218
# Install globally
158219
npm install -g mcp-openapi-server
159220

160-
# Run in stdio mode (for IDE integration)
221+
# Run in stdio mode (default - for IDE integration)
161222
mcp-openapi-server --specs ./specs --config ./mcp-config.json
162223

163-
# Run in HTTP mode (for web integration)
224+
# Run in HTTP mode (for web integration and testing)
164225
mcp-openapi-server --http --port 4000 --specs ./specs --config ./mcp-config.json
165226

166227
# Run with custom base URL (overrides config file setting)
167228
mcp-openapi-server --base-url https://api.example.com --specs ./specs --config ./mcp-config.json
229+
230+
# Stdio mode with custom base URL (for production MCP servers)
231+
mcp-openapi-server --base-url https://api.production.com --specs ./specs --config ./mcp-config.json
168232
```
169233

170234
#### Docker Usage
171235
```bash
172236
# Build Docker image
173237
docker build -t mcp-openapi-server .
174238

175-
# Run container
239+
# Run container in HTTP mode (for web deployment)
176240
docker run -p 4000:4000 -v ./specs:/app/specs -v ./config:/app/config mcp-openapi-server --http --port 4000
241+
242+
# Run container in stdio mode (for MCP integration - requires interactive mode)
243+
docker run -i -v ./specs:/app/specs -v ./config:/app/config mcp-openapi-server
177244
```
178245

179246
### 2. Library Integration
@@ -199,8 +266,11 @@ const mcpServer = new MCPOpenAPIServer({
199266

200267
await mcpServer.initialize();
201268

202-
// Run in HTTP mode
203-
await mcpServer.runHttp(4000);
269+
// Run in stdio mode (default - for MCP integration)
270+
await mcpServer.runStdio();
271+
272+
// OR run in HTTP mode (for web integration)
273+
// await mcpServer.runHttp(4000);
204274
```
205275

206276
#### Express.js Integration
@@ -535,16 +605,20 @@ interface ServerOptions {
535605

536606
```
537607
Options:
538-
-s, --specs <dir> Directory containing OpenAPI specifications (default: "./specs")
539-
-c, --config <file> Configuration file path (default: "./mcp-config.json")
540-
-p, --prompts <dir> Directory containing prompt specifications (default: "./prompts")
608+
-s, --specs <dir> Directory containing OpenAPI specifications (default: "./examples/specs")
609+
-c, --config <file> Configuration file path (default: "./examples/mcp-config.json")
610+
-p, --prompts <dir> Directory containing prompt specifications (default: "./examples/prompts")
541611
--port <number> Port for HTTP server mode (default: "4000")
542612
--base-url <url> Base URL for backend APIs (overrides config file)
543-
--http Run in HTTP server mode instead of stdio
544-
-v, --verbose Enable verbose logging
613+
--http Run in HTTP server mode instead of stdio (default: false)
614+
-v, --verbose Enable verbose logging (default: true)
545615
-h, --help Display help for command
546616
```
547617

618+
**Mode Selection:**
619+
- **Default (no `--http` flag):** Stdio mode - ideal for IDE integration (Cursor, Claude Desktop)
620+
- **With `--http` flag:** HTTP mode - ideal for web integration, testing, and standalone deployment
621+
548622
## HTTP Endpoints (HTTP Mode)
549623

550624
When running with `--http`, the server exposes:

mcp-openapi/examples/mcp-config.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,23 @@
1313
"specId": "banking-payments",
1414
"path": "/v1/banking/payments",
1515
"method": "get",
16-
"type": "resource",
17-
"toolName": "get_payments",
16+
"type": "tool",
17+
"toolName": "banking-payments_get_payments",
1818
"description": "Search payments by various criteria. CRITICAL: This API has NO category or type parameters. Available parameters ONLY: accountId, payeeId, amount, payeeName (exact names only), productName, startDate, endDate, maxResult. For business payment searches: (1) FIRST call this with accountId parameter ONLY, (2) Get payment results containing payeeId fields, (3) THEN call payee resources for EACH payeeId to get category information, (4) FINALLY filter results where payee.category='business'. DO NOT use non-existent parameters like 'category' or 'type'. DO NOT use payeeName='business' - that searches for a payee literally named 'business'."
1919
},
2020
{
2121
"specId": "banking-payees",
2222
"path": "/v1/banking/payees",
2323
"method": "get",
24-
"type": "resource",
24+
"type": "tool",
2525
"description": "ESSENTIAL for business payment analysis: List payee profiles with category information. This resource contains the critical 'category' field (business, personal, family, utilities, etc.) that payment records lack. WORKFLOW: After getting payment data, use this resource to get category info for multiple payees. Supports 'category' parameter for direct filtering (e.g., category='business'). Use this as step 2 in business payment analysis workflow."
2626
},
2727
{
2828
"specId": "banking-payees",
2929
"path": "/v1/banking/payees/{payeeId}",
3030
"method": "get",
31-
"type": "resource",
31+
"type": "tool",
32+
"toolName": "banking-payees_get_payee_by_id",
3233
"description": "REQUIRED for individual payee category lookup: Get specific payee details including the essential 'category' field. WORKFLOW: After getting payment results, call this resource for each payeeId found in payments to determine if that payee is categorized as 'business', 'personal', etc. This is step 2b in business payment analysis - get individual payee categories to filter business payments."
3334
}
3435
]

mcp-openapi/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
},
99
"type": "module",
1010
"scripts": {
11-
"dev": "BANKING_API_TOKEN=mcp-service-token-demo-123 tsx src/cli.ts --specs ./examples/specs --config ./examples/mcp-config.json --prompts ./examples/prompts --verbose",
12-
"dev:clean": "tsx src/cli.ts",
11+
"dev": "BANKING_API_TOKEN=mcp-service-token-demo-123 tsx src/cli.ts --specs ./examples/specs --config ./examples/mcp-config.json --prompts ./examples/prompts --verbose --http",
12+
"dev:stdio": "tsx src/cli.ts",
1313
"build": "tsc",
14-
"start": "node dist/cli.js",
14+
"start": "node dist/cli.js --http --port 4000",
15+
"start:stdio": "node dist/cli.js",
1516
"start:http": "node dist/cli.js --http --port 4000",
1617
"cli": "tsx src/cli.ts",
1718
"test": "jest",

mcp-openapi/src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ program
1717
.option('-p, --prompts <dir>', 'Directory containing prompt specifications', './examples/prompts')
1818
.option('--port <number>', 'Port for HTTP server mode', '4000')
1919
.option('--base-url <url>', 'Base URL for backend APIs (overrides config file)')
20-
.option('--http', 'Run in HTTP server mode instead of stdio', true)
20+
.option('--http', 'Run in HTTP server mode instead of stdio', false)
2121
.option('-v, --verbose', 'Enable verbose logging', true)
2222
.action(async (options) => {
2323
const serverOptions: ServerOptions = {

0 commit comments

Comments
 (0)