@parlex/collector-sdk 0.1.0
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 +194 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware.d.ts +27 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +102 -0
- package/dist/middleware.js.map +1 -0
- package/dist/types.d.ts +39 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +38 -0
package/README.md
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# @mcp-server/collector-sdk
|
|
2
|
+
|
|
3
|
+
Express middleware for collecting API traffic and sending it to an MCP server for automatic tool generation.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @mcp-server/collector-sdk
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @mcp-server/collector-sdk
|
|
11
|
+
# or
|
|
12
|
+
yarn add @mcp-server/collector-sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import express from 'express';
|
|
19
|
+
import { createCollector } from '@mcp-server/collector-sdk';
|
|
20
|
+
|
|
21
|
+
const app = express();
|
|
22
|
+
|
|
23
|
+
// Add the collector middleware
|
|
24
|
+
app.use(createCollector({
|
|
25
|
+
mcpUrl: process.env.MCP_SERVER_URL, // e.g., 'https://mcp.example.com'
|
|
26
|
+
apiKey: process.env.COLLECTOR_API_KEY, // Your collector API key
|
|
27
|
+
debug: process.env.NODE_ENV !== 'production'
|
|
28
|
+
}));
|
|
29
|
+
|
|
30
|
+
// Your API routes
|
|
31
|
+
app.get('/api/users', (req, res) => {
|
|
32
|
+
res.json({ users: [] });
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
app.listen(3000);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Configuration
|
|
39
|
+
|
|
40
|
+
### Required Options
|
|
41
|
+
|
|
42
|
+
- **`mcpUrl`** (string): Base URL of your MCP server
|
|
43
|
+
- **`apiKey`** (string): API key for authenticating with the collector endpoint
|
|
44
|
+
|
|
45
|
+
### Optional Options
|
|
46
|
+
|
|
47
|
+
- **`collectPath`** (string): Custom collector endpoint path (default: `'/collect'`)
|
|
48
|
+
- **`debug`** (boolean): Enable debug logging (default: `false`)
|
|
49
|
+
- **`timeout`** (number): Request timeout in milliseconds (default: `5000`)
|
|
50
|
+
- **`shouldCollect`** (function): Filter which requests to collect
|
|
51
|
+
|
|
52
|
+
## Advanced Usage
|
|
53
|
+
|
|
54
|
+
### Filtering Requests
|
|
55
|
+
|
|
56
|
+
Only collect specific endpoints:
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
app.use(createCollector({
|
|
60
|
+
mcpUrl: process.env.MCP_SERVER_URL,
|
|
61
|
+
apiKey: process.env.COLLECTOR_API_KEY,
|
|
62
|
+
shouldCollect: (req) => {
|
|
63
|
+
// Only collect /api/* endpoints
|
|
64
|
+
return req.path.startsWith('/api/');
|
|
65
|
+
}
|
|
66
|
+
}));
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Environment Variables
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# .env
|
|
73
|
+
MCP_SERVER_URL=https://mcp.yourcompany.com
|
|
74
|
+
COLLECTOR_API_KEY=your-secret-key-here
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
import { config } from 'dotenv';
|
|
79
|
+
config();
|
|
80
|
+
|
|
81
|
+
app.use(createCollector({
|
|
82
|
+
mcpUrl: process.env.MCP_SERVER_URL!,
|
|
83
|
+
apiKey: process.env.COLLECTOR_API_KEY!,
|
|
84
|
+
debug: process.env.NODE_ENV !== 'production'
|
|
85
|
+
}));
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Debug Mode
|
|
89
|
+
|
|
90
|
+
Enable detailed logging:
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
app.use(createCollector({
|
|
94
|
+
mcpUrl: 'https://mcp.example.com',
|
|
95
|
+
apiKey: 'your-key',
|
|
96
|
+
debug: true
|
|
97
|
+
}));
|
|
98
|
+
|
|
99
|
+
// Output:
|
|
100
|
+
// [MCP Collector] Initialized with URL: https://mcp.example.com/collect
|
|
101
|
+
// [MCP Collector] Capturing: GET /api/users
|
|
102
|
+
// [MCP Collector] Sending: GET /api/users - Status: 200 - Duration: 45ms
|
|
103
|
+
// [MCP Collector] ✓ Sent: GET /api/users
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## What Gets Collected
|
|
107
|
+
|
|
108
|
+
For each request/response, the following data is collected:
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
{
|
|
112
|
+
method: 'GET',
|
|
113
|
+
path: '/api/users?page=1',
|
|
114
|
+
query: { page: '1' },
|
|
115
|
+
body: null,
|
|
116
|
+
response: { users: [...] },
|
|
117
|
+
status: 200,
|
|
118
|
+
durationMs: 45,
|
|
119
|
+
timestamp: '2026-01-22T10:30:00.000Z'
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Error Handling
|
|
124
|
+
|
|
125
|
+
The collector middleware:
|
|
126
|
+
- ✅ Never blocks your API responses
|
|
127
|
+
- ✅ Sends data asynchronously after the response is sent
|
|
128
|
+
- ✅ Logs errors only, doesn't throw
|
|
129
|
+
- ✅ Won't crash your app if MCP server is down
|
|
130
|
+
|
|
131
|
+
## TypeScript Support
|
|
132
|
+
|
|
133
|
+
Full TypeScript support with exported types:
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
import { CollectorConfig, CollectorEntry } from '@mcp-server/collector-sdk';
|
|
137
|
+
|
|
138
|
+
const config: CollectorConfig = {
|
|
139
|
+
mcpUrl: 'https://mcp.example.com',
|
|
140
|
+
apiKey: 'your-key'
|
|
141
|
+
};
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Examples
|
|
145
|
+
|
|
146
|
+
### Express + TypeScript
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
import express, { Express } from 'express';
|
|
150
|
+
import { createCollector } from '@mcp-server/collector-sdk';
|
|
151
|
+
|
|
152
|
+
const app: Express = express();
|
|
153
|
+
|
|
154
|
+
app.use(express.json());
|
|
155
|
+
app.use(createCollector({
|
|
156
|
+
mcpUrl: process.env.MCP_SERVER_URL!,
|
|
157
|
+
apiKey: process.env.COLLECTOR_API_KEY!
|
|
158
|
+
}));
|
|
159
|
+
|
|
160
|
+
app.get('/api/users', (req, res) => {
|
|
161
|
+
res.json({ users: [] });
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
app.listen(3000, () => {
|
|
165
|
+
console.log('Server running on port 3000');
|
|
166
|
+
});
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### With Custom Timeout
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
app.use(createCollector({
|
|
173
|
+
mcpUrl: 'https://mcp.example.com',
|
|
174
|
+
apiKey: 'your-key',
|
|
175
|
+
timeout: 10000 // 10 seconds
|
|
176
|
+
}));
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Excluding Health Checks
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
app.use(createCollector({
|
|
183
|
+
mcpUrl: 'https://mcp.example.com',
|
|
184
|
+
apiKey: 'your-key',
|
|
185
|
+
shouldCollect: (req) => {
|
|
186
|
+
// Don't collect health check endpoints
|
|
187
|
+
return !req.path.startsWith('/health');
|
|
188
|
+
}
|
|
189
|
+
}));
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## License
|
|
193
|
+
|
|
194
|
+
ISC
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @mcp-server/collector-sdk
|
|
3
|
+
*
|
|
4
|
+
* Express middleware for collecting API traffic and sending to MCP server
|
|
5
|
+
* for automatic tool generation.
|
|
6
|
+
*/
|
|
7
|
+
export { createCollector, collectorMiddleware } from './middleware.js';
|
|
8
|
+
export type { CollectorConfig, CollectorEntry } from './types.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACvE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Request, Response, NextFunction } from 'express';
|
|
2
|
+
import { CollectorConfig } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Create Express middleware that collects request/response data
|
|
5
|
+
* and sends it to an MCP server
|
|
6
|
+
*
|
|
7
|
+
* @param config - Collector configuration
|
|
8
|
+
* @returns Express middleware function
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { createCollector } from '@mcp-server/collector-sdk';
|
|
13
|
+
*
|
|
14
|
+
* app.use(createCollector({
|
|
15
|
+
* mcpUrl: 'https://mcp.example.com',
|
|
16
|
+
* apiKey: process.env.COLLECTOR_API_KEY,
|
|
17
|
+
* debug: true
|
|
18
|
+
* }));
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function createCollector(config: CollectorConfig): (req: Request, res: Response, next: NextFunction) => void;
|
|
22
|
+
/**
|
|
23
|
+
* Legacy function name for backward compatibility
|
|
24
|
+
* @deprecated Use createCollector instead
|
|
25
|
+
*/
|
|
26
|
+
export declare function collectorMiddleware(mcpUrl: string, apiKey: string): (req: Request, res: Response, next: NextFunction) => void;
|
|
27
|
+
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAkB,MAAM,YAAY,CAAC;AAE7D;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,IAgB7C,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,UAmFxD;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,SAzFnD,OAAO,OAAO,QAAQ,QAAQ,YAAY,UA2FxD"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
/**
|
|
3
|
+
* Create Express middleware that collects request/response data
|
|
4
|
+
* and sends it to an MCP server
|
|
5
|
+
*
|
|
6
|
+
* @param config - Collector configuration
|
|
7
|
+
* @returns Express middleware function
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { createCollector } from '@mcp-server/collector-sdk';
|
|
12
|
+
*
|
|
13
|
+
* app.use(createCollector({
|
|
14
|
+
* mcpUrl: 'https://mcp.example.com',
|
|
15
|
+
* apiKey: process.env.COLLECTOR_API_KEY,
|
|
16
|
+
* debug: true
|
|
17
|
+
* }));
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export function createCollector(config) {
|
|
21
|
+
const { mcpUrl, apiKey, collectPath = '/collect', debug = false, timeout = 5000, shouldCollect = () => true } = config;
|
|
22
|
+
const collectorUrl = `${mcpUrl}${collectPath}`;
|
|
23
|
+
if (debug) {
|
|
24
|
+
console.log(`[MCP Collector] Initialized with URL: ${collectorUrl}`);
|
|
25
|
+
}
|
|
26
|
+
return (req, res, next) => {
|
|
27
|
+
// Skip if filter says no
|
|
28
|
+
if (!shouldCollect(req)) {
|
|
29
|
+
return next();
|
|
30
|
+
}
|
|
31
|
+
const start = Date.now();
|
|
32
|
+
// Save the request body before Express processes it
|
|
33
|
+
const requestBody = req.body;
|
|
34
|
+
// Capture response body
|
|
35
|
+
let responseBody;
|
|
36
|
+
const originalSend = res.send;
|
|
37
|
+
res.send = function (body) {
|
|
38
|
+
responseBody = body;
|
|
39
|
+
return originalSend.call(this, body);
|
|
40
|
+
};
|
|
41
|
+
if (debug) {
|
|
42
|
+
console.log(`[MCP Collector] Capturing: ${req.method} ${req.originalUrl}`);
|
|
43
|
+
}
|
|
44
|
+
// When the response is finished
|
|
45
|
+
res.on('finish', async () => {
|
|
46
|
+
try {
|
|
47
|
+
// Try to parse response if it's a JSON string
|
|
48
|
+
let finalResponse = responseBody;
|
|
49
|
+
try {
|
|
50
|
+
if (typeof responseBody === 'string' &&
|
|
51
|
+
(responseBody.startsWith('{') || responseBody.startsWith('['))) {
|
|
52
|
+
finalResponse = JSON.parse(responseBody);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
// If parsing fails, use original body
|
|
57
|
+
}
|
|
58
|
+
const entry = {
|
|
59
|
+
method: req.method,
|
|
60
|
+
path: req.originalUrl,
|
|
61
|
+
query: req.query,
|
|
62
|
+
body: requestBody,
|
|
63
|
+
response: finalResponse,
|
|
64
|
+
status: res.statusCode,
|
|
65
|
+
durationMs: Date.now() - start,
|
|
66
|
+
timestamp: new Date().toISOString(),
|
|
67
|
+
};
|
|
68
|
+
if (debug) {
|
|
69
|
+
console.log(`[MCP Collector] Sending: ${req.method} ${req.originalUrl} ` +
|
|
70
|
+
`- Status: ${res.statusCode} - Duration: ${entry.durationMs}ms`);
|
|
71
|
+
}
|
|
72
|
+
// Send to collector asynchronously without blocking
|
|
73
|
+
await axios.post(collectorUrl, entry, {
|
|
74
|
+
headers: {
|
|
75
|
+
'Content-Type': 'application/json',
|
|
76
|
+
'x-collector-key': apiKey
|
|
77
|
+
},
|
|
78
|
+
timeout
|
|
79
|
+
});
|
|
80
|
+
if (debug) {
|
|
81
|
+
console.log(`[MCP Collector] ✓ Sent: ${req.method} ${req.originalUrl}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
// Log error but don't fail the request
|
|
86
|
+
const axiosError = error;
|
|
87
|
+
if (debug || axiosError.response?.status === 401) {
|
|
88
|
+
console.error(`[MCP Collector] ✗ Failed to send: ${req.method} ${req.originalUrl}`, axiosError.message, axiosError.response?.status === 401 ? '(Unauthorized - check API key)' : '');
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
next();
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Legacy function name for backward compatibility
|
|
97
|
+
* @deprecated Use createCollector instead
|
|
98
|
+
*/
|
|
99
|
+
export function collectorMiddleware(mcpUrl, apiKey) {
|
|
100
|
+
return createCollector({ mcpUrl, apiKey });
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAqB,MAAM,OAAO,CAAC;AAI1C;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,eAAe,CAAC,MAAuB;IACrD,MAAM,EACJ,MAAM,EACN,MAAM,EACN,WAAW,GAAG,UAAU,EACxB,KAAK,GAAG,KAAK,EACb,OAAO,GAAG,I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ACX,qCAAqC,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,WAAW,EAAE,EACpE,UAAU,CAAC,OAAO,EAClB,UAAU,CAAC,QAAQ,EAAE,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,gCAAgC,CAAC,CAAC,CAAC,EAAE,CAC5E,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,IAAI,EAAE,CAAC;IACT,CAAC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAc,EAAE,MAAc;IAChE,OAAO,eAAe,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;AAC7C,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entry data collected from a request/response cycle
|
|
3
|
+
*/
|
|
4
|
+
export interface CollectorEntry {
|
|
5
|
+
/** HTTP method (GET, POST, etc.) */
|
|
6
|
+
method: string;
|
|
7
|
+
/** Request path with query string */
|
|
8
|
+
path: string;
|
|
9
|
+
/** Query parameters */
|
|
10
|
+
query: Record<string, any>;
|
|
11
|
+
/** Request body */
|
|
12
|
+
body: any;
|
|
13
|
+
/** Response body */
|
|
14
|
+
response?: any;
|
|
15
|
+
/** HTTP status code */
|
|
16
|
+
status: number;
|
|
17
|
+
/** Request duration in milliseconds */
|
|
18
|
+
durationMs: number;
|
|
19
|
+
/** ISO timestamp */
|
|
20
|
+
timestamp: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Configuration options for the collector middleware
|
|
24
|
+
*/
|
|
25
|
+
export interface CollectorConfig {
|
|
26
|
+
/** Base URL of the MCP server (e.g., 'https://mcp.example.com') */
|
|
27
|
+
mcpUrl: string;
|
|
28
|
+
/** API key for authenticating with the collector endpoint */
|
|
29
|
+
apiKey: string;
|
|
30
|
+
/** Optional: Custom endpoint path (default: '/collect') */
|
|
31
|
+
collectPath?: string;
|
|
32
|
+
/** Optional: Enable debug logging (default: false) */
|
|
33
|
+
debug?: boolean;
|
|
34
|
+
/** Optional: Timeout for collector requests in ms (default: 5000) */
|
|
35
|
+
timeout?: number;
|
|
36
|
+
/** Optional: Filter function to determine which requests to collect */
|
|
37
|
+
shouldCollect?: (req: any) => boolean;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,oCAAoC;IACpC,MAAM,EAAE,MAAM,CAAC;IAEf,qCAAqC;IACrC,IAAI,EAAE,MAAM,CAAC;IAEb,uBAAuB;IACvB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAE3B,mBAAmB;IACnB,IAAI,EAAE,GAAG,CAAC;IAEV,oBAAoB;IACpB,QAAQ,CAAC,EAAE,GAAG,CAAC;IAEf,uBAAuB;IACvB,MAAM,EAAE,MAAM,CAAC;IAEf,uCAAuC;IACvC,UAAU,EAAE,MAAM,CAAC;IAEnB,oBAAoB;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,mEAAmE;IACnE,MAAM,EAAE,MAAM,CAAC;IAEf,6DAA6D;IAC7D,MAAM,EAAE,MAAM,CAAC;IAEf,2DAA2D;IAC3D,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,sDAAsD;IACtD,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB,qEAAqE;IACrE,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,uEAAuE;IACvE,aAAa,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC;CACvC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@parlex/collector-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Express middleware for collecting API traffic and sending to MCP server",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"dev": "tsc --watch",
|
|
15
|
+
"prepublishOnly": "npm run build"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"mcp",
|
|
19
|
+
"collector",
|
|
20
|
+
"express",
|
|
21
|
+
"middleware",
|
|
22
|
+
"api",
|
|
23
|
+
"traffic"
|
|
24
|
+
],
|
|
25
|
+
"author": "",
|
|
26
|
+
"license": "ISC",
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"express": "^4.0.0"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"axios": "^1.7.7"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/express": "^4.17.21",
|
|
35
|
+
"@types/node": "^22.9.0",
|
|
36
|
+
"typescript": "^5.6.3"
|
|
37
|
+
}
|
|
38
|
+
}
|