-
Notifications
You must be signed in to change notification settings - Fork 0
MCP API Service Example
Status: ✅ Complete
Last Updated: December 6, 2025
This example demonstrates integrating an API service MCP server with RiceCoder. The API server provides tools for making HTTP requests to external APIs.
# Install via npm
npm install -g api-mcp-server
# Or use Node.js directly
node ./api-server.jsCreate .ricecoder/mcp-servers.yaml:
servers:
- id: api-server
name: API Tools
command: node
args:
- ./api-server.js
- --port
- "3000"
env:
API_KEY: ${API_KEY}
API_URL: https://api.example.com
API_TIMEOUT: "10000"
LOG_LEVEL: INFO
timeout_ms: 10000
auto_reconnect: true
max_retries: 5export API_KEY=your_api_keyricecoder tools listExpected output:
Available Tools:
api-get (api-server)
Description: Make GET request to API
Category: api
Parameters: endpoint (string, required), headers (object, optional)
Returns: object
api-post (api-server)
Description: Make POST request to API
Category: api
Parameters: endpoint (string, required), data (object, required), headers (object, optional)
Returns: object
api-put (api-server)
Description: Make PUT request to API
Category: api
Parameters: endpoint (string, required), data (object, required), headers (object, optional)
Returns: object
api-delete (api-server)
Description: Make DELETE request to API
Category: api
Parameters: endpoint (string, required), headers (object, optional)
Returns: object
Create .ricecoder/permissions.yaml:
permissions:
# Allow all GET requests (read-only)
- pattern: "api-get"
level: allow
# Ask for POST requests (create)
- pattern: "api-post"
level: ask
# Ask for PUT requests (update)
- pattern: "api-put"
level: ask
# Ask for DELETE requests (delete)
- pattern: "api-delete"
level: askricecoder tools invoke api-get \
--endpoint "/users/123"Output:
{
"success": true,
"status": 200,
"data": {
"id": 123,
"name": "Alice",
"email": "alice@example.com",
"created_at": "2025-01-01T00:00:00Z"
}
}ricecoder tools invoke api-post \
--endpoint "/users" \
--data '{"name": "Bob", "email": "bob@example.com"}'Output:
{
"success": true,
"status": 201,
"data": {
"id": 124,
"name": "Bob",
"email": "bob@example.com",
"created_at": "2025-01-15T10:30:00Z"
}
}ricecoder tools invoke api-put \
--endpoint "/users/123" \
--data '{"name": "Alice Updated", "email": "alice.updated@example.com"}'Output:
{
"success": true,
"status": 200,
"data": {
"id": 123,
"name": "Alice Updated",
"email": "alice.updated@example.com",
"updated_at": "2025-01-15T11:00:00Z"
}
}ricecoder tools invoke api-delete \
--endpoint "/users/124"Output:
{
"success": true,
"status": 204,
"message": "User deleted successfully"
}ricecoder tools invoke api-get \
--endpoint "/users" \
--headers '{"Accept": "application/json", "X-Custom-Header": "value"}'Output:
{
"success": true,
"status": 200,
"data": [
{
"id": 123,
"name": "Alice",
"email": "alice@example.com"
},
{
"id": 124,
"name": "Bob",
"email": "bob@example.com"
}
]
}The code generator can use API tools to:
- Fetch API specifications
- Generate code from API responses
- Create API client code
// Fetch API specification
let spec = agent.invoke_tool("api-get",
json!({"endpoint": "/api/spec"})
).await?;
// Generate code from spec
let generated_code = generate_client_code(&spec);
// Return generated code
Ok(generated_code)The data sync agent can use API tools to:
- Fetch data from external APIs
- Transform and store data
- Keep data in sync
// Fetch data from API
let users = agent.invoke_tool("api-get",
json!({"endpoint": "/users"})
).await?;
// Transform data
let transformed = transform_users(&users);
// Store in local database
store_users(&transformed).await?;The integration agent can use API tools to:
- Integrate with third-party services
- Sync data between systems
- Trigger external workflows
// Fetch data from source API
let data = agent.invoke_tool("api-get",
json!({"endpoint": "/source/data"})
).await?;
// Send to destination API
agent.invoke_tool("api-post",
json!({
"endpoint": "/destination/data",
"data": data
})
).await?;servers:
- id: api-server
name: API Tools
command: node
args:
- ./api-server.js
- --port
- "3000"
env:
API_KEY: ${API_KEY}
API_URL: https://api.example.com
API_TIMEOUT: "10000"
LOG_LEVEL: INFO
timeout_ms: 10000
auto_reconnect: true
max_retries: 5permissions:
# Allow all GET requests (read-only)
- pattern: "api-get"
level: allow
# Ask for POST requests (create)
- pattern: "api-post"
level: ask
# Ask for PUT requests (update)
- pattern: "api-put"
level: ask
# Ask for DELETE requests (delete)
- pattern: "api-delete"
level: ask
# Per-agent: Allow data sync agent to write
- pattern: "api-post"
level: allow
agent_id: data-sync
- pattern: "api-put"
level: allow
agent_id: data-syncError: API request failed with status 404
Output:
{
"success": false,
"status": 404,
"error": "Not Found",
"message": "Resource not found"
}Solutions:
- Check endpoint is correct
- Verify resource exists
- Check API documentation
Error: API request failed with status 401
Output:
{
"success": false,
"status": 401,
"error": "Unauthorized",
"message": "Invalid API key"
}Solutions:
- Check API key is set:
export API_KEY=... - Verify API key is valid
- Check API key has required permissions
Error: Tool 'api-get' timed out after 10000ms
Solutions:
- Increase timeout:
timeout_ms: 15000 - Check API server performance
- Check network connectivity
- Optimize API request
Error: Failed to start API server
Solutions:
- Check Node.js is installed:
node --version - Check API server script exists:
ls ./api-server.js - Check port is available:
lsof -i :3000 - Check environment variables are set
Error: Failed to connect to API server
Solutions:
- Check API server is running:
ps aux | grep api-server - Check port is correct:
--port 3000 - Check network connectivity
- Restart API server
Error: Permission denied for tool 'api-post'
Solutions:
- Check permissions in
.ricecoder/permissions.yaml - Verify permission level is not "deny"
- Check per-agent permissions
- Update permissions if needed
Last updated: December 6, 2025