@awarecorp/mcp-logger 0.0.3-dev.5 → 0.0.3-dev.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +257 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
# @awarecorp/mcp-logger
|
|
2
|
+
|
|
3
|
+
**Unified MCP Observability Solution** - Monitor your Model Context Protocol servers with zero configuration.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@awarecorp/mcp-logger)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
[Aware Corp](https://awarecorp.io/)
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 🎯 Overview
|
|
13
|
+
|
|
14
|
+
`@awarecorp/mcp-logger` provides comprehensive observability for MCP servers in two ways:
|
|
15
|
+
|
|
16
|
+
- **SDK**: Direct integration for custom MCP servers
|
|
17
|
+
- **CLI**: Zero-code wrapper for existing MCP packages
|
|
18
|
+
|
|
19
|
+
All telemetry data is sent to OpenTelemetry-compatible endpoints with automatic request-response pairing.
|
|
20
|
+
|
|
21
|
+
## 📦 Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install @awarecorp/mcp-logger
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 🚀 Quick Start
|
|
28
|
+
|
|
29
|
+
### SDK Mode
|
|
30
|
+
|
|
31
|
+
Instrument your MCP server with one line of code:
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { trace } from "@awarecorp/mcp-logger";
|
|
35
|
+
|
|
36
|
+
trace(server, {
|
|
37
|
+
apiKey: "YOUR_API_KEY",
|
|
38
|
+
serviceName: "my-mcp-server",
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### CLI Mode
|
|
43
|
+
|
|
44
|
+
Wrap any existing MCP server without code changes:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npx @awarecorp/mcp-logger \
|
|
48
|
+
-k YOUR_API_KEY \
|
|
49
|
+
-s my-server \
|
|
50
|
+
npx your-mcp-server
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## 📋 Features
|
|
54
|
+
|
|
55
|
+
### Core Capabilities
|
|
56
|
+
|
|
57
|
+
- **Automatic Request-Response Pairing**: Single span per request-response cycle with intelligent message correlation
|
|
58
|
+
- **Notification Support**: Tracks both client→server and server→client notifications
|
|
59
|
+
- **Selective Method Tracking**: Configurable filtering to track only relevant methods (excludes noisy notifications like `notifications/initialized`)
|
|
60
|
+
- **Custom Event Logging**: Add context-aware logs within request handlers
|
|
61
|
+
- **Enhanced Error Handling**: Robust error serialization for complex error objects
|
|
62
|
+
- **Custom OTLP Endpoint**: Send traces to any OTLP/HTTP compatible observability backend
|
|
63
|
+
- **Transport Support**: stdio and SSE (Server-Sent Events)
|
|
64
|
+
- **Zero Configuration**: Works out of the box with sensible defaults
|
|
65
|
+
|
|
66
|
+
### Telemetry Data
|
|
67
|
+
|
|
68
|
+
All spans include:
|
|
69
|
+
|
|
70
|
+
- Request/response timestamps and payloads
|
|
71
|
+
- Method name and parameters
|
|
72
|
+
- Tool names and arguments (for `tools/call`)
|
|
73
|
+
- Custom events and logs
|
|
74
|
+
- Error details (if any)
|
|
75
|
+
- Duration metrics
|
|
76
|
+
- CLI server information (command, args, env)
|
|
77
|
+
|
|
78
|
+
### Data Format
|
|
79
|
+
|
|
80
|
+
Optimized for Elasticsearch with flat structure:
|
|
81
|
+
|
|
82
|
+
- `mcp.request.method` / `mcp.response.method`: Method names for request/response
|
|
83
|
+
- `mcp.source`: `sdk` or `cli`
|
|
84
|
+
- `mcp.transport`: `stdio` or `sse`
|
|
85
|
+
- `mcp.duration_ms`: Request duration
|
|
86
|
+
- `mcp.tool.name`: Tool name (tools/call only)
|
|
87
|
+
- `mcp.request.params` / `mcp.response.result`: Request/response payloads
|
|
88
|
+
- `mcp.error.message`: Enhanced error serialization (no more `[object Object]`)
|
|
89
|
+
- `mcp.events`: Custom log entries (JSON array)
|
|
90
|
+
- `mcp.cli.server`: CLI execution info (JSON object)
|
|
91
|
+
|
|
92
|
+
## 🔧 SDK API
|
|
93
|
+
|
|
94
|
+
### `trace(server, options)`
|
|
95
|
+
|
|
96
|
+
Enable automatic instrumentation on an MCP server.
|
|
97
|
+
|
|
98
|
+
**Parameters:**
|
|
99
|
+
|
|
100
|
+
- `server`: MCP Server instance
|
|
101
|
+
- `options.apiKey`: API key for authentication (required)
|
|
102
|
+
- Currently accepts any string value for testing purposes
|
|
103
|
+
- For production use, sign up at [Aware](https://awarecorp.io/) to get your API key
|
|
104
|
+
- `options.serviceName`: Service identifier (optional, auto-generated if omitted)
|
|
105
|
+
- `options.endpoint`: Custom OTLP endpoint (optional, default: `https://aware.mcypher.com/v1/traces`)
|
|
106
|
+
- Accepts any OTLP/HTTP compatible endpoint URL
|
|
107
|
+
- Use this to send traces to your own observability backend (e.g., Jaeger, Grafana, etc.)
|
|
108
|
+
- `options.debug`: Enable debug logging (optional, default: false)
|
|
109
|
+
|
|
110
|
+
**Returns:** `void`
|
|
111
|
+
|
|
112
|
+
### `trace.addLog(entry)`
|
|
113
|
+
|
|
114
|
+
Add custom log entries within request handlers.
|
|
115
|
+
|
|
116
|
+
**Parameters:**
|
|
117
|
+
|
|
118
|
+
- `entry.level`: Log level (`info` | `warn` | `error`)
|
|
119
|
+
- `entry.message`: Log message (required)
|
|
120
|
+
- `entry.metadata`: Additional data (optional)
|
|
121
|
+
- `entry.timestamp`: Unix timestamp in milliseconds (optional, auto-generated)
|
|
122
|
+
|
|
123
|
+
**Returns:** `void`
|
|
124
|
+
|
|
125
|
+
### `trace.shutdown()`
|
|
126
|
+
|
|
127
|
+
Gracefully shutdown telemetry and flush pending data.
|
|
128
|
+
|
|
129
|
+
**Returns:** `Promise<void>`
|
|
130
|
+
|
|
131
|
+
## 🖥️ CLI Usage
|
|
132
|
+
|
|
133
|
+
### Basic Syntax
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
mcp-logger [options] <command...>
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Options
|
|
140
|
+
|
|
141
|
+
- `-k, --api-key <key>`: API key (required)
|
|
142
|
+
- Currently accepts any string value for testing
|
|
143
|
+
- Sign up at [Aware](https://awarecorp.io/) to get your API key for production use
|
|
144
|
+
- `-s, --service-name <name>`: Service name (optional)
|
|
145
|
+
- `-e, --endpoint <url>`: Custom OTLP endpoint (optional, default: `https://aware.mcypher.com/v1/traces`)
|
|
146
|
+
- Send traces to any OTLP/HTTP compatible backend
|
|
147
|
+
- Examples: Jaeger, Grafana Tempo, New Relic, Honeycomb, etc.
|
|
148
|
+
- `-d, --debug`: Enable debug logging (optional)
|
|
149
|
+
- Shows detailed information about message processing and span creation
|
|
150
|
+
|
|
151
|
+
### Examples
|
|
152
|
+
|
|
153
|
+
**Wrap an npx command:**
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
mcp-logger -k API_KEY -s filesystem npx -y @modelcontextprotocol/server-filesystem /path
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
**Use with Claude Desktop:**
|
|
160
|
+
|
|
161
|
+
```json
|
|
162
|
+
{
|
|
163
|
+
"mcpServers": {
|
|
164
|
+
"my-server": {
|
|
165
|
+
"command": "npx",
|
|
166
|
+
"args": [
|
|
167
|
+
"-y",
|
|
168
|
+
"@awarecorp/mcp-logger",
|
|
169
|
+
"-k",
|
|
170
|
+
"YOUR_API_KEY",
|
|
171
|
+
"-s",
|
|
172
|
+
"my-server",
|
|
173
|
+
"--",
|
|
174
|
+
"npx",
|
|
175
|
+
"-y",
|
|
176
|
+
"your-mcp-server"
|
|
177
|
+
]
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## 🏗️ How It Works
|
|
184
|
+
|
|
185
|
+
### Request-Response Pairing
|
|
186
|
+
|
|
187
|
+
Creates **one span per request-response pair** for complete transaction context:
|
|
188
|
+
|
|
189
|
+
1. Request arrives → stored in pending map
|
|
190
|
+
2. Response arrives → matched by ID, single span created
|
|
191
|
+
3. Timeout (30s) → pending requests cleared
|
|
192
|
+
4. Notifications → handled as single-direction spans (request-only or response-only)
|
|
193
|
+
|
|
194
|
+
### Message Type Handling
|
|
195
|
+
|
|
196
|
+
- **Paired Spans**: Request-response cycles with matching IDs (most common)
|
|
197
|
+
- **Request-Only Spans**: Client→server notifications (no response expected)
|
|
198
|
+
- **Response-Only Spans**: Server→client notifications (no matching request)
|
|
199
|
+
|
|
200
|
+
### Tracked Methods
|
|
201
|
+
|
|
202
|
+
Configurable method filtering with exclusion list:
|
|
203
|
+
|
|
204
|
+
- Tracks: `tools/call`, `tools/list`, and other business-critical methods
|
|
205
|
+
- Excludes: `notifications/initialized` and other noisy protocol notifications
|
|
206
|
+
- Customizable via `EXCLUDED_METHODS` configuration
|
|
207
|
+
|
|
208
|
+
## 📊 Telemetry Data Structure
|
|
209
|
+
|
|
210
|
+
Each span includes:
|
|
211
|
+
|
|
212
|
+
- Request/response timestamps and payloads (with optional fields for notifications)
|
|
213
|
+
- Method name and parameters (separate fields for request/response)
|
|
214
|
+
- Tool names and arguments (for `tools/call`)
|
|
215
|
+
- Custom events and logs
|
|
216
|
+
- Enhanced error details with proper serialization
|
|
217
|
+
- Duration metrics
|
|
218
|
+
- CLI server information (command, args, env)
|
|
219
|
+
|
|
220
|
+
### Span Attributes
|
|
221
|
+
|
|
222
|
+
All attributes use a flat structure optimized for Elasticsearch:
|
|
223
|
+
|
|
224
|
+
**Core Attributes:**
|
|
225
|
+
|
|
226
|
+
- Request attributes: `mcp.request.*` (id, method, params, timestamp)
|
|
227
|
+
- Response attributes: `mcp.response.*` (method, result, error, timestamp)
|
|
228
|
+
- Error handling: Proper serialization for Error objects, strings, and complex objects
|
|
229
|
+
- Metadata: source, transport, duration, tool information
|
|
230
|
+
|
|
231
|
+
**Context Tracking:**
|
|
232
|
+
|
|
233
|
+
- `mcp.session.id`: Unique session identifier
|
|
234
|
+
- `mcp.conversation.id`: Conversation/thread identifier
|
|
235
|
+
- `mcp.user.id`: User identifier (from params, headers, or environment)
|
|
236
|
+
- `mcp.client.name`: Client application name (e.g., 'Claude Desktop')
|
|
237
|
+
- `mcp.client.version`: Client version
|
|
238
|
+
|
|
239
|
+
**Permission & Security:**
|
|
240
|
+
|
|
241
|
+
- `mcp.permission.level`: Permission level (read/write/admin/elevated)
|
|
242
|
+
|
|
243
|
+
**Resource Tracking:**
|
|
244
|
+
|
|
245
|
+
- `mcp.resource.type`: Resource type (tool/file/prompt)
|
|
246
|
+
- `mcp.resource.uri`: Resource URI or identifier
|
|
247
|
+
- `mcp.resource.access_count`: Number of times resource accessed
|
|
248
|
+
|
|
249
|
+
## 📄 License
|
|
250
|
+
|
|
251
|
+
MIT © [Aware Corp](https://awarecorp.io/)
|
|
252
|
+
|
|
253
|
+
## 🔗 Links
|
|
254
|
+
|
|
255
|
+
- [Aware Corp](https://awarecorp.io/)
|
|
256
|
+
- [npm Package](https://www.npmjs.com/package/@awarecorp/mcp-logger)
|
|
257
|
+
- [Model Context Protocol](https://modelcontextprotocol.io/)
|
package/package.json
CHANGED