# MCP Swagger Server(mss)
Status code filtering (repeatable) [Example: 200]
--operation-filter-parameters Parameter filtering (repeatable) [Example: userId]
```
> Note: to use direct mode with `mss`, you must pass `--openapi`. If your OpenAPI spec uses relative `servers.url` values (for example `/v1`), prefer loading from a remote URL, or set `--base-url` explicitly. Swagger 2.0 specs are auto-converted to OpenAPI 3.x on startup (including `host/basePath` mapping).
#### Examples
```bash
# Use local OpenAPI file
mss --openapi ./swagger.json --transport sse --port 3322
# Use remote OpenAPI URL
mss --openapi https://api.example.com/openapi.json --transport streamable --port 3323
# Monitor file changes
mss --openapi ./api.yaml --transport stdio --watch
# Use Bearer Token authentication
mss --openapi https://api.example.com/openapi.json --auth-type bearer --bearer-token "your-token-here" --transport sse --port 3322
# Read token from environment variable
export API_TOKEN="your-token-here"
mss --openapi https://api.example.com/openapi.json --auth-type bearer --bearer-env API_TOKEN --transport stdio
# Using operation filtering options
# Include only GET and POST method endpoints
mss --openapi https://api.example.com/openapi.json \
--operation-filter-methods GET \
--operation-filter-methods POST \
--transport streamable
# Include only specific path endpoints
mss --openapi https://api.example.com/openapi.json \
--operation-filter-paths "/api/users/*" \
--operation-filter-paths "/api/orders/*" \
--transport streamable
# Include only specific operation ID endpoints
mss --openapi https://api.example.com/openapi.json \
--operation-filter-operation-ids "getUserById" \
--operation-filter-operation-ids "createUser" \
--transport streamable
# Include only specific status code endpoints
mss --openapi https://api.example.com/openapi.json \
--operation-filter-status-codes "200" \
--operation-filter-status-codes "201" \
--operation-filter-status-codes "204" \
--transport streamable
# Include only endpoints with specific parameters
mss --openapi https://api.example.com/openapi.json \
--operation-filter-parameters "userId" \
--operation-filter-parameters "email" \
--transport streamable
# Combine multiple filtering options
mss --openapi https://api.example.com/openapi.json \
--operation-filter-methods GET \
--operation-filter-methods POST \
--operation-filter-paths "/api/users/*" \
--operation-filter-status-codes "200" \
--operation-filter-status-codes "201" \
--transport streamable
```
### π Bearer Token Authentication
`mcp-swagger-server` supports Bearer Token authentication to protect API access that requires authentication.
#### Authentication Methods
**1. Direct Token Specification**
```bash
mss --auth-type bearer --bearer-token "your-token-here" --openapi https://api.example.com/openapi.json --transport streamable
```
**2. Environment Variable Method**
```bash
# Set environment variable
export API_TOKEN="your-token-here"
# Use environment variable
mss --auth-type bearer --bearer-env API_TOKEN --openapi https://api.example.com/openapi.json
```
**3. Configuration File Method**
```json
{
"transport": "sse",
"port": 3322,
"openapi": "https://api.example.com/openapi.json",
"auth": {
"type": "bearer",
"bearer": {
"token": "your-token-here",
"source": "static"
}
}
}
```
```bash
# Use configuration file
mss --config config.json
```
#### Environment Variable Configuration
Create a `.env` file:
```env
# Basic configuration
MCP_PORT=3322
MCP_TRANSPORT=stdio
MCP_OPENAPI_URL=https://api.example.com/openapi.json
MCP_ENDPOINT=/mcp
MCP_BASE_URL=https://api.example.com/v1
# Authentication configuration
MCP_AUTH_TYPE=bearer
API_TOKEN=your-bearer-token-here
```
### π€ AI Assistant Integration
#### Claude Desktop Configuration
```json
{
"mcpServers": {
"swagger-converter": {
"command": "mss",
"args": [
"--openapi", "https://petstore.swagger.io/v2/swagger.json",
"--transport", "stdio"
]
},
"secured-api": {
"command": "mss",
"args": [
"--openapi", "https://api.example.com/openapi.json",
"--transport", "stdio",
"--auth-type", "bearer",
"--bearer-env", "API_TOKEN"
],
"env": {
"API_TOKEN": "your-bearer-token-here"
}
}
}
}
```
#### Programmatic Usage
```typescript
import axios from 'axios';
import { createMcpServer, startStreamableMcpServer } from 'mcp-swagger-server';
const openApiData = (await axios.get('https://api.example.com/openapi.json')).data;
const server = await createMcpServer({
openApiData,
authConfig: {
type: 'bearer',
bearer: {
source: 'static',
token: 'your-token-here'
}
}
});
await startStreamableMcpServer(server, '/mcp', 3322);
```
## π οΈ Development
### Build System
```bash
# Build all packages
pnpm build
# Build core workspace packages
pnpm build:packages
# Terminal development mode (CLI / parser watch)
pnpm dev
# Clean build artifacts
pnpm clean
```
### Testing and Debugging
```bash
# Run tests
pnpm test
# Code linting
pnpm lint
# Type checking
pnpm type-check
# Project health check
pnpm diagnostic
```
### MCP Server Development
```bash
cd packages/mcp-swagger-server
# Development mode startup
pnpm dev
# Run CLI tools
pnpm cli --help
# Debug with MCP Inspector
npx @modelcontextprotocol/inspector node dist/index.js
```
## π Project Status
| Package | Status | Description |
|---------|--------|-------------|
| `mcp-swagger-server` | β
Available | Core MCP server with multi-transport support |
| `mcp-swagger-parser` | β
Available | OpenAPI parser and conversion tools |
| `mcp-swagger-api` | β
Available | NestJS REST API backend |
## π€ Contributing
Contributions are welcome! Please read the [Contributing Guide](CONTRIBUTING.md) first.
## π License
MIT License - see the [LICENSE](LICENSE) file for details.
---
**Built with β€οΈ by ZhaoYaNan(ZTE)**
[β Star](../../stargazers) β’ [π Issues](../../issues) β’ [π¬ Discussions](../../discussions)