You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+104Lines changed: 104 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -112,6 +112,110 @@ const client = new McpdClient({
112
112
});
113
113
```
114
114
115
+
### Logging
116
+
117
+
The SDK includes optional logging for warnings about unhealthy or non-existent servers that are skipped during operations.
118
+
119
+
**Important:** Logging is disabled by default. Only enable logging in non-MCP-server contexts. MCP servers using stdio transport for JSON-RPC communication should never enable logging, as it will contaminate stdout/stderr and break the protocol.
120
+
121
+
#### Using Environment Variable
122
+
123
+
Set the `MCPD_LOG_LEVEL` environment variable to control logging:
124
+
125
+
```bash
126
+
# Valid levels: trace, debug, info, warn, error, off (default)
// Logging is automatically enabled based on MCPD_LOG_LEVEL
143
+
const client =newMcpdClient({
144
+
apiEndpoint: "http://localhost:8090",
145
+
});
146
+
```
147
+
148
+
#### Using Custom Logger
149
+
150
+
For advanced use cases, inject your own logger implementation.
151
+
152
+
**Partial Logger Support:** You can provide only the methods you want to customize. Any omitted methods will fall back to the default logger, which respects `MCPD_LOG_LEVEL`.
153
+
154
+
```typescript
155
+
import { McpdClient } from"@mozilla-ai/mcpd";
156
+
157
+
// Full custom logger
158
+
const client =newMcpdClient({
159
+
apiEndpoint: "http://localhost:8090",
160
+
logger: {
161
+
trace: (...args) =>myLogger.trace(args),
162
+
debug: (...args) =>myLogger.debug(args),
163
+
info: (...args) =>myLogger.info(args),
164
+
warn: (...args) =>myLogger.warn(args),
165
+
error: (...args) =>myLogger.error(args),
166
+
},
167
+
});
168
+
169
+
// Partial logger: custom warn/error, default (MCPD_LOG_LEVEL-aware) for others
170
+
const client2 =newMcpdClient({
171
+
apiEndpoint: "http://localhost:8090",
172
+
logger: {
173
+
warn: (msg) =>console.warn(`[mcpd] ${msg}`),
174
+
error: (msg) =>console.error(`[mcpd] ${msg}`),
175
+
// trace, debug, info use default logger (respects MCPD_LOG_LEVEL)
176
+
},
177
+
});
178
+
```
179
+
180
+
#### Disabling Logging
181
+
182
+
To disable logging, simply ensure `MCPD_LOG_LEVEL` is unset or set to `off` (the default):
183
+
184
+
```typescript
185
+
// Logging is disabled by default (no configuration needed)
186
+
const client =newMcpdClient({
187
+
apiEndpoint: "http://localhost:8090",
188
+
});
189
+
```
190
+
191
+
If you need to disable logging even when `MCPD_LOG_LEVEL` is set (rare case), provide a custom logger with no-op implementations:
192
+
193
+
```typescript
194
+
// Override MCPD_LOG_LEVEL to force disable
195
+
const client =newMcpdClient({
196
+
apiEndpoint: "http://localhost:8090",
197
+
logger: {
198
+
trace: () => {},
199
+
debug: () => {},
200
+
info: () => {},
201
+
warn: () => {},
202
+
error: () => {},
203
+
},
204
+
});
205
+
```
206
+
207
+
When logging is enabled, warnings are emitted for:
208
+
209
+
- Unhealthy servers that are skipped (e.g., status `timeout`, `unreachable`)
210
+
- Non-existent servers specified in filter options
211
+
212
+
Example warning messages:
213
+
214
+
```text
215
+
Skipping unhealthy server 'time' with status 'timeout'
0 commit comments