Files
mcp-proc/examples/README.md
2025-10-11 03:22:03 +02:00

135 líneas
2.7 KiB
Markdown

# Examples
This directory contains example code demonstrating how to use the MCP ProcFS Server.
## Files
### `basic-usage.ts`
TypeScript example showing how to use the ProcFS reader and writer libraries directly.
**Run:**
```bash
cd /path/to/mcp-proc
npm install
npm run build
npx tsx examples/basic-usage.ts
```
### `python-client.py`
Python example demonstrating how to interact with the HTTP API.
**Requirements:**
```bash
pip install requests
```
**Run:**
```bash
# Start the server first
npm run start:sse
# In another terminal
python examples/python-client.py
```
### `monitoring-dashboard.js`
Real-time system monitoring dashboard using Server-Sent Events (SSE).
**Requirements:**
```bash
npm install eventsource node-fetch
```
**Run:**
```bash
# Start the server first
npm run start:sse
# In another terminal
node examples/monitoring-dashboard.js
```
### `mcp-config.json`
Example MCP client configuration file. Use this with MCP-compatible clients like Claude Desktop.
**Usage:**
1. Copy to your MCP client config location
2. Update the path to point to your installation
3. Restart your MCP client
For Claude Desktop on macOS:
```bash
cp examples/mcp-config.json ~/Library/Application\ Support/Claude/claude_desktop_config.json
```
## More Examples
### Using cURL
```bash
# Start the HTTP server
npm run start:sse
# Get CPU information
curl http://localhost:3000/api/cpu
# Get memory info
curl http://localhost:3000/api/memory
# Read a sysctl parameter
curl http://localhost:3000/api/sysctl/kernel.hostname
# Write a sysctl parameter (requires permissions)
curl -X POST http://localhost:3000/api/sysctl \
-H "Content-Type: application/json" \
-d '{"key": "vm.swappiness", "value": 10}'
```
### Using JavaScript Fetch API
```javascript
// Get CPU information
const response = await fetch('http://localhost:3000/api/cpu');
const data = await response.json();
console.log(data);
// Write sysctl parameter
await fetch('http://localhost:3000/api/sysctl', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
key: 'net.ipv4.ip_forward',
value: 1
})
});
```
### Using the MCP Protocol
```bash
# Start the MCP server on stdio
npm start
# Send a JSON-RPC request (via stdin)
echo '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' | npm start
```
## Interactive API Documentation
The HTTP server includes interactive Swagger documentation:
1. Start the server: `npm run start:sse`
2. Open browser: http://localhost:3000/api-docs
3. Try out the endpoints directly from the browser
## Need Help?
- Check the [API Documentation](../docs/API.md)
- See [Quick Start Guide](../docs/QUICKSTART.md)
- Review the [main README](../README.md)