API Key Authentication Guide
Overview
The Schema.org MCP server includes built-in API key authentication for secure external access. All requests to protected endpoints require a valid API key.
Quick Start
1. Get Your API Key
On first server startup, a default API key is automatically generated and logged:
Default API key: sk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxThis key is stored in .api-keys.json in the project directory.
2. Use the API Key
Include the API key in your requests using one of these methods:
Authorization Header (Recommended):
curl -H "Authorization: Bearer sk_your_api_key" \
https://json-ld-schema-mcp.serptransformer.com/sseX-API-Key Header:
curl -H "X-API-Key: sk_your_api_key" \
https://json-ld-schema-mcp.serptransformer.com/sseQuery Parameter:
curl "https://json-ld-schema-mcp.serptransformer.com/sse?api_key=sk_your_api_key"API Key Format
API keys follow the format: sk_ followed by 64 random hexadecimal characters.
Example: sk_a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6a7b8c9d0e1f2
Configuration
Environment Variables
| Variable | Default | Purpose |
|---|---|---|
REQUIRE_AUTH | true | Enable/disable API key authentication |
API_KEYS_CONFIG | .api-keys.json | Path to API keys configuration file |
Disable Authentication (Development Only)
REQUIRE_AUTH=false USE_SSE=true SSE_PORT=3000 node dist/index.jsAPI Keys Configuration File
The API keys are stored in .api-keys.json:
{
"sk_abcdef1234567890...": {
"key": "sk_abcdef1234567890...",
"name": "default-key",
"enabled": true,
"createdAt": "2025-12-23T07:00:00.000Z",
"lastUsed": "2025-12-23T07:05:00.000Z",
"rateLimit": null
},
"sk_fedcba0987654321...": {
"key": "sk_fedcba0987654321...",
"name": "production-key",
"enabled": true,
"createdAt": "2025-12-23T06:00:00.000Z",
"lastUsed": "2025-12-23T07:04:00.000Z",
"rateLimit": 1000
}
}File Permissions: The file is created with mode 0600 (read/write for owner only). Keep this secure!
Managing API Keys
View API Keys
List all API keys (requires authentication):
curl -H "Authorization: Bearer sk_your_api_key" \
https://json-ld-schema-mcp.serptransformer.com/api-keysResponse:
{
"keys": [
{
"name": "default-key",
"enabled": true,
"createdAt": "2025-12-23T07:00:00.000Z",
"lastUsed": "2025-12-23T07:05:00.000Z"
},
{
"name": "production-key",
"enabled": true,
"createdAt": "2025-12-23T06:00:00.000Z",
"lastUsed": "2025-12-23T07:04:00.000Z"
}
]
}Generate New Keys
Edit .api-keys.json and add a new entry:
{
"sk_newkey1234567890abcdef...": {
"key": "sk_newkey1234567890abcdef...",
"name": "my-app-key",
"enabled": true,
"createdAt": "2025-12-23T07:10:00.000Z",
"rateLimit": 500
}
}Or use a Node.js script:
import { ApiKeyManager } from './dist/auth.js';
const manager = new ApiKeyManager();
const newKey = manager.addKey('my-app-key', 500); // 500 requests/hour
console.log('New API Key:', newKey);Revoke a Key
Set "enabled": false in .api-keys.json:
{
"sk_oldkey1234567890abcdef...": {
"key": "sk_oldkey1234567890abcdef...",
"name": "old-key",
"enabled": false,
"createdAt": "2025-12-23T06:00:00.000Z"
}
}Revoked keys will immediately be rejected for all requests.
Protected Endpoints
The following endpoints require API key authentication:
GET /sse- SSE connection endpointPOST /messages- Message POST endpointGET /api-keys- List API keys
Public Endpoints
These endpoints do NOT require authentication:
GET /health- Health check
Error Responses
Missing or Invalid API Key
Status Code: 401 Unauthorized
{
"error": "Unauthorized: Invalid or missing API key"
}Malformed Request
Status Code: 400 Bad Request
{
"error": "Invalid JSON"
}Not Found
Status Code: 404 Not Found
{
"error": "Not found"
}Security Best Practices
-
Keep Keys Secure
- Never commit
.api-keys.jsonto version control - Use environment variables or secure vaults for production
- Restrict file permissions to
0600
- Never commit
-
Rotate Keys Regularly
- Generate new keys periodically
- Revoke old keys after rotation
- Track key creation and last usage dates
-
Use Unique Keys Per Application
- Create separate keys for each client/application
- Easier to revoke if a key is compromised
- Better audit trail
-
Monitor Key Usage
- Check
lastUsedtimestamps regularly - Investigate unused keys
- Remove keys that haven't been used in 90 days
- Check
-
HTTPS Only
- Always use HTTPS for API requests
- Never send API keys over unencrypted connections
- Use TLS 1.2 or higher
Integration Examples
Node.js/TypeScript
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
const apiKey = process.env.SCHEMA_ORG_API_KEY;
const transport = new SSEClientTransport({
url: 'https://json-ld-schema-mcp.serptransformer.com/sse',
headers: {
'Authorization': `Bearer ${apiKey}`,
},
});
const client = new Client({
name: 'schema-org-client',
version: '1.0.0',
}, {
capabilities: {},
});
await client.connect(transport);Python
import requests
from sseclient import SSEClient
import os
api_key = os.getenv('SCHEMA_ORG_API_KEY')
headers = {
'Authorization': f'Bearer {api_key}',
'Content-Type': 'application/json',
}
url = 'https://json-ld-schema-mcp.serptransformer.com/sse'
client = SSEClient(url, headers=headers)
for event in client:
if event.event == 'message':
print(f"Received: {event.data}")cURL
# Using environment variable
API_KEY="sk_your_api_key"
# SSE connection
curl -H "Authorization: Bearer $API_KEY" \
https://json-ld-schema-mcp.serptransformer.com/sse
# List API keys
curl -H "Authorization: Bearer $API_KEY" \
https://json-ld-schema-mcp.serptransformer.com/api-keys
# Health check (no auth required)
curl https://json-ld-schema-mcp.serptransformer.com/healthTroubleshooting
"Unauthorized: Invalid or missing API key"
- Verify the API key is correct
- Check the key is enabled in
.api-keys.json - Ensure the key is included in the request headers
- Verify HTTPS is being used
API Key Not Working After Update
- Restart the server:
sudo systemctl restart schema-org-mcp - Check
.api-keys.jsonis valid JSON - Verify file permissions:
ls -la .api-keys.json - Check server logs:
sudo journalctl -u schema-org-mcp -f
Lost Default API Key
If you lose the default API key:
- Stop the server:
sudo systemctl stop schema-org-mcp - Delete
.api-keys.json - Start the server:
sudo systemctl start schema-org-mcp - A new default key will be generated and logged
Rate Limiting (Future)
The API key structure supports per-key rate limiting (currently not enforced):
{
"sk_key...": {
"name": "limited-key",
"rateLimit": 100
}
}Rate limiting will be implemented in a future release.