mcp-http-webhook 1.0.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/.eslintrc.json +16 -0
- package/.prettierrc.json +8 -0
- package/ARCHITECTURE.md +269 -0
- package/CONTRIBUTING.md +136 -0
- package/GETTING_STARTED.md +310 -0
- package/IMPLEMENTATION.md +294 -0
- package/LICENSE +21 -0
- package/MIGRATION_TO_SDK.md +263 -0
- package/README.md +496 -0
- package/SDK_INTEGRATION_COMPLETE.md +300 -0
- package/STANDARD_SUBSCRIPTIONS.md +268 -0
- package/STANDARD_SUBSCRIPTIONS_COMPLETE.md +309 -0
- package/SUMMARY.md +272 -0
- package/Spec.md +2778 -0
- package/dist/errors/index.d.ts +52 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +81 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol/ProtocolHandler.d.ts +37 -0
- package/dist/protocol/ProtocolHandler.d.ts.map +1 -0
- package/dist/protocol/ProtocolHandler.js +172 -0
- package/dist/protocol/ProtocolHandler.js.map +1 -0
- package/dist/server.d.ts +6 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +502 -0
- package/dist/server.js.map +1 -0
- package/dist/stores/InMemoryStore.d.ts +27 -0
- package/dist/stores/InMemoryStore.d.ts.map +1 -0
- package/dist/stores/InMemoryStore.js +73 -0
- package/dist/stores/InMemoryStore.js.map +1 -0
- package/dist/stores/RedisStore.d.ts +18 -0
- package/dist/stores/RedisStore.d.ts.map +1 -0
- package/dist/stores/RedisStore.js +45 -0
- package/dist/stores/RedisStore.js.map +1 -0
- package/dist/stores/index.d.ts +3 -0
- package/dist/stores/index.d.ts.map +1 -0
- package/dist/stores/index.js +9 -0
- package/dist/stores/index.js.map +1 -0
- package/dist/subscriptions/SubscriptionManager.d.ts +49 -0
- package/dist/subscriptions/SubscriptionManager.d.ts.map +1 -0
- package/dist/subscriptions/SubscriptionManager.js +181 -0
- package/dist/subscriptions/SubscriptionManager.js.map +1 -0
- package/dist/types/index.d.ts +271 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +16 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/index.d.ts +51 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +154 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/webhooks/WebhookManager.d.ts +27 -0
- package/dist/webhooks/WebhookManager.d.ts.map +1 -0
- package/dist/webhooks/WebhookManager.js +174 -0
- package/dist/webhooks/WebhookManager.js.map +1 -0
- package/examples/GITHUB_LIVE_EXAMPLE.md +308 -0
- package/examples/GITHUB_LIVE_SETUP.md +253 -0
- package/examples/QUICKSTART.md +130 -0
- package/examples/basic-setup.ts +142 -0
- package/examples/github-server-live.ts +690 -0
- package/examples/github-server.ts +223 -0
- package/examples/google-drive-server-live.ts +773 -0
- package/examples/start-github-live.sh +53 -0
- package/jest.config.js +20 -0
- package/package.json +58 -0
- package/src/errors/index.ts +81 -0
- package/src/index.ts +19 -0
- package/src/server.ts +595 -0
- package/src/stores/InMemoryStore.ts +87 -0
- package/src/stores/RedisStore.ts +51 -0
- package/src/stores/index.ts +2 -0
- package/src/subscriptions/SubscriptionManager.ts +240 -0
- package/src/types/index.ts +341 -0
- package/src/utils/index.ts +156 -0
- package/src/webhooks/WebhookManager.ts +230 -0
- package/test-sdk-integration.sh +157 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RedisStore = void 0;
|
|
4
|
+
exports.createRedisStore = createRedisStore;
|
|
5
|
+
/**
|
|
6
|
+
* Redis store implementation
|
|
7
|
+
* Requires ioredis package
|
|
8
|
+
*/
|
|
9
|
+
class RedisStore {
|
|
10
|
+
constructor(redis) {
|
|
11
|
+
this.redis = redis;
|
|
12
|
+
} // ioredis instance
|
|
13
|
+
async get(key) {
|
|
14
|
+
return await this.redis.get(key);
|
|
15
|
+
}
|
|
16
|
+
async set(key, value, ttl) {
|
|
17
|
+
if (ttl) {
|
|
18
|
+
await this.redis.setex(key, ttl, value);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
await this.redis.set(key, value);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async delete(key) {
|
|
25
|
+
await this.redis.del(key);
|
|
26
|
+
}
|
|
27
|
+
async scan(pattern) {
|
|
28
|
+
const keys = [];
|
|
29
|
+
let cursor = '0';
|
|
30
|
+
do {
|
|
31
|
+
const [newCursor, matches] = await this.redis.scan(cursor, 'MATCH', pattern, 'COUNT', 100);
|
|
32
|
+
cursor = newCursor;
|
|
33
|
+
keys.push(...matches);
|
|
34
|
+
} while (cursor !== '0');
|
|
35
|
+
return keys;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.RedisStore = RedisStore;
|
|
39
|
+
/**
|
|
40
|
+
* Create Redis store from connection URL
|
|
41
|
+
*/
|
|
42
|
+
function createRedisStore(redis) {
|
|
43
|
+
return new RedisStore(redis);
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=RedisStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RedisStore.js","sourceRoot":"","sources":["../../src/stores/RedisStore.ts"],"names":[],"mappings":";;;AAgDA,4CAEC;AAhDD;;;GAGG;AACH,MAAa,UAAU;IACrB,YAAoB,KAAU;QAAV,UAAK,GAAL,KAAK,CAAK;IAAG,CAAC,CAAC,mBAAmB;IAEtD,KAAK,CAAC,GAAG,CAAC,GAAW;QACnB,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,KAAa,EAAE,GAAY;QAChD,IAAI,GAAG,EAAE,CAAC;YACR,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;QAC1C,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAW;QACtB,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,OAAe;QACxB,MAAM,IAAI,GAAa,EAAE,CAAC;QAC1B,IAAI,MAAM,GAAG,GAAG,CAAC;QAEjB,GAAG,CAAC;YACF,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAChD,MAAM,EACN,OAAO,EACP,OAAO,EACP,OAAO,EACP,GAAG,CACJ,CAAC;YACF,MAAM,GAAG,SAAS,CAAC;YACnB,IAAI,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC;QACxB,CAAC,QAAQ,MAAM,KAAK,GAAG,EAAE;QAEzB,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AArCD,gCAqCC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAC,KAAU;IACzC,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/stores/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRedisStore = exports.RedisStore = exports.InMemoryStore = void 0;
|
|
4
|
+
var InMemoryStore_1 = require("./InMemoryStore");
|
|
5
|
+
Object.defineProperty(exports, "InMemoryStore", { enumerable: true, get: function () { return InMemoryStore_1.InMemoryStore; } });
|
|
6
|
+
var RedisStore_1 = require("./RedisStore");
|
|
7
|
+
Object.defineProperty(exports, "RedisStore", { enumerable: true, get: function () { return RedisStore_1.RedisStore; } });
|
|
8
|
+
Object.defineProperty(exports, "createRedisStore", { enumerable: true, get: function () { return RedisStore_1.createRedisStore; } });
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/stores/index.ts"],"names":[],"mappings":";;;AAAA,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AACtB,2CAA4D;AAAnD,wGAAA,UAAU,OAAA;AAAE,8GAAA,gBAAgB,OAAA"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { AuthContext, KeyValueStore, Logger, ResourceDefinition, StoredSubscription } from '../types';
|
|
2
|
+
export declare class SubscriptionManager {
|
|
3
|
+
private store;
|
|
4
|
+
private resources;
|
|
5
|
+
private publicUrl;
|
|
6
|
+
private logger?;
|
|
7
|
+
constructor(store: KeyValueStore, resources: ResourceDefinition[], publicUrl: string, logger?: Logger | undefined);
|
|
8
|
+
/**
|
|
9
|
+
* Create a new subscription
|
|
10
|
+
*/
|
|
11
|
+
createSubscription(params: {
|
|
12
|
+
uri: string;
|
|
13
|
+
clientCallbackUrl: string;
|
|
14
|
+
clientCallbackSecret?: string;
|
|
15
|
+
context: AuthContext;
|
|
16
|
+
}): Promise<{
|
|
17
|
+
subscriptionId: string;
|
|
18
|
+
status: string;
|
|
19
|
+
}>;
|
|
20
|
+
/**
|
|
21
|
+
* Delete a subscription
|
|
22
|
+
*/
|
|
23
|
+
deleteSubscription(subscriptionId: string, context: AuthContext): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Get subscription by ID
|
|
26
|
+
*/
|
|
27
|
+
getSubscription(subscriptionId: string): Promise<StoredSubscription | null>;
|
|
28
|
+
/**
|
|
29
|
+
* List subscriptions for a user
|
|
30
|
+
*/
|
|
31
|
+
listSubscriptions(userId: string): Promise<StoredSubscription[]>;
|
|
32
|
+
/**
|
|
33
|
+
* Store subscription data
|
|
34
|
+
*/
|
|
35
|
+
private storeSubscription;
|
|
36
|
+
/**
|
|
37
|
+
* Load subscription data
|
|
38
|
+
*/
|
|
39
|
+
private loadSubscription;
|
|
40
|
+
/**
|
|
41
|
+
* Remove subscription data
|
|
42
|
+
*/
|
|
43
|
+
private removeSubscription;
|
|
44
|
+
/**
|
|
45
|
+
* Find resource definition for URI
|
|
46
|
+
*/
|
|
47
|
+
private findResourceForUri;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=SubscriptionManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SubscriptionManager.d.ts","sourceRoot":"","sources":["../../src/subscriptions/SubscriptionManager.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,aAAa,EACb,MAAM,EACN,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,UAAU,CAAC;AAGlB,qBAAa,mBAAmB;IAE5B,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,MAAM,CAAC;gBAHP,KAAK,EAAE,aAAa,EACpB,SAAS,EAAE,kBAAkB,EAAE,EAC/B,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,MAAM,YAAA;IAGzB;;OAEG;IACG,kBAAkB,CAAC,MAAM,EAAE;QAC/B,GAAG,EAAE,MAAM,CAAC;QACZ,iBAAiB,EAAE,MAAM,CAAC;QAC1B,oBAAoB,CAAC,EAAE,MAAM,CAAC;QAC9B,OAAO,EAAE,WAAW,CAAC;KACtB,GAAG,OAAO,CAAC;QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IA6DvD;;OAEG;IACG,kBAAkB,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IA6CrF;;OAEG;IACG,eAAe,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;IAIjF;;OAEG;IACG,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAiBtE;;OAEG;YACW,iBAAiB;IAmB/B;;OAEG;YACW,gBAAgB;IAW9B;;OAEG;YACW,kBAAkB;IAehC;;OAEG;IACH,OAAO,CAAC,kBAAkB;CAoB3B"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SubscriptionManager = void 0;
|
|
4
|
+
const errors_1 = require("../errors");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
class SubscriptionManager {
|
|
7
|
+
constructor(store, resources, publicUrl, logger) {
|
|
8
|
+
this.store = store;
|
|
9
|
+
this.resources = resources;
|
|
10
|
+
this.publicUrl = publicUrl;
|
|
11
|
+
this.logger = logger;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Create a new subscription
|
|
15
|
+
*/
|
|
16
|
+
async createSubscription(params) {
|
|
17
|
+
const { uri, clientCallbackUrl, clientCallbackSecret, context } = params;
|
|
18
|
+
// Find resource definition
|
|
19
|
+
const resource = this.findResourceForUri(uri);
|
|
20
|
+
if (!resource) {
|
|
21
|
+
throw new errors_1.ValidationError(`No resource found for URI: ${uri}`);
|
|
22
|
+
}
|
|
23
|
+
if (!resource.subscription) {
|
|
24
|
+
throw new errors_1.ValidationError(`Resource ${resource.name} does not support subscriptions`);
|
|
25
|
+
}
|
|
26
|
+
// Generate subscription ID
|
|
27
|
+
const subscriptionId = (0, utils_1.generateSubscriptionId)();
|
|
28
|
+
const thirdPartyWebhookUrl = (0, utils_1.generateWebhookUrl)(this.publicUrl, subscriptionId);
|
|
29
|
+
this.logger?.info('Creating subscription', {
|
|
30
|
+
subscriptionId,
|
|
31
|
+
uri,
|
|
32
|
+
clientCallbackUrl,
|
|
33
|
+
});
|
|
34
|
+
try {
|
|
35
|
+
// Call resource's onSubscribe handler
|
|
36
|
+
const metadata = await resource.subscription.onSubscribe(uri, subscriptionId, thirdPartyWebhookUrl, context);
|
|
37
|
+
// Store subscription data
|
|
38
|
+
const subscriptionData = {
|
|
39
|
+
uri,
|
|
40
|
+
resourceType: resource.name,
|
|
41
|
+
clientCallbackUrl,
|
|
42
|
+
clientCallbackSecret,
|
|
43
|
+
userId: context.userId,
|
|
44
|
+
thirdPartyWebhookId: metadata.thirdPartyWebhookId,
|
|
45
|
+
metadata: metadata.metadata,
|
|
46
|
+
createdAt: Date.now(),
|
|
47
|
+
};
|
|
48
|
+
await this.storeSubscription(subscriptionId, subscriptionData, context.userId);
|
|
49
|
+
this.logger?.info('Subscription created', { subscriptionId });
|
|
50
|
+
return {
|
|
51
|
+
subscriptionId,
|
|
52
|
+
status: 'active',
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
this.logger?.error('Failed to create subscription', {
|
|
57
|
+
subscriptionId,
|
|
58
|
+
error: error instanceof Error ? error.message : String(error),
|
|
59
|
+
});
|
|
60
|
+
throw new errors_1.StorageError('Failed to create subscription', { cause: error });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Delete a subscription
|
|
65
|
+
*/
|
|
66
|
+
async deleteSubscription(subscriptionId, context) {
|
|
67
|
+
this.logger?.info('Deleting subscription', { subscriptionId });
|
|
68
|
+
// Load subscription
|
|
69
|
+
const subscription = await this.loadSubscription(subscriptionId);
|
|
70
|
+
if (!subscription) {
|
|
71
|
+
throw new errors_1.ValidationError(`Subscription ${subscriptionId} not found`);
|
|
72
|
+
}
|
|
73
|
+
// Verify ownership
|
|
74
|
+
if (subscription.userId !== context.userId) {
|
|
75
|
+
throw new errors_1.ValidationError('Unauthorized to delete this subscription');
|
|
76
|
+
}
|
|
77
|
+
// Find resource
|
|
78
|
+
const resource = this.findResourceForUri(subscription.uri);
|
|
79
|
+
if (!resource?.subscription) {
|
|
80
|
+
throw new errors_1.StorageError('Resource subscription configuration not found');
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
// Call resource's onUnsubscribe handler
|
|
84
|
+
await resource.subscription.onUnsubscribe(subscription.uri, subscriptionId, {
|
|
85
|
+
thirdPartyWebhookId: subscription.thirdPartyWebhookId,
|
|
86
|
+
metadata: subscription.metadata,
|
|
87
|
+
}, context);
|
|
88
|
+
// Delete from store
|
|
89
|
+
await this.removeSubscription(subscriptionId, context.userId);
|
|
90
|
+
this.logger?.info('Subscription deleted', { subscriptionId });
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
this.logger?.error('Failed to delete subscription', {
|
|
94
|
+
subscriptionId,
|
|
95
|
+
error: error instanceof Error ? error.message : String(error),
|
|
96
|
+
});
|
|
97
|
+
throw new errors_1.StorageError('Failed to delete subscription', { cause: error });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Get subscription by ID
|
|
102
|
+
*/
|
|
103
|
+
async getSubscription(subscriptionId) {
|
|
104
|
+
return this.loadSubscription(subscriptionId);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* List subscriptions for a user
|
|
108
|
+
*/
|
|
109
|
+
async listSubscriptions(userId) {
|
|
110
|
+
const indexKey = `user:${userId}:subscriptions`;
|
|
111
|
+
const indexData = await this.store.get(indexKey);
|
|
112
|
+
if (!indexData) {
|
|
113
|
+
return [];
|
|
114
|
+
}
|
|
115
|
+
const subscriptionIds = JSON.parse(indexData);
|
|
116
|
+
const subscriptions = await Promise.all(subscriptionIds.map((id) => this.loadSubscription(id)));
|
|
117
|
+
return subscriptions.filter((s) => s !== null);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Store subscription data
|
|
121
|
+
*/
|
|
122
|
+
async storeSubscription(subscriptionId, data, userId) {
|
|
123
|
+
const key = `subscription:${subscriptionId}`;
|
|
124
|
+
await this.store.set(key, JSON.stringify(data));
|
|
125
|
+
// Update user index
|
|
126
|
+
const indexKey = `user:${userId}:subscriptions`;
|
|
127
|
+
const existing = await this.store.get(indexKey);
|
|
128
|
+
const subscriptionIds = existing ? JSON.parse(existing) : [];
|
|
129
|
+
if (!subscriptionIds.includes(subscriptionId)) {
|
|
130
|
+
subscriptionIds.push(subscriptionId);
|
|
131
|
+
await this.store.set(indexKey, JSON.stringify(subscriptionIds));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Load subscription data
|
|
136
|
+
*/
|
|
137
|
+
async loadSubscription(subscriptionId) {
|
|
138
|
+
const key = `subscription:${subscriptionId}`;
|
|
139
|
+
const data = await this.store.get(key);
|
|
140
|
+
if (!data) {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
return JSON.parse(data);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Remove subscription data
|
|
147
|
+
*/
|
|
148
|
+
async removeSubscription(subscriptionId, userId) {
|
|
149
|
+
const key = `subscription:${subscriptionId}`;
|
|
150
|
+
await this.store.delete(key);
|
|
151
|
+
// Update user index
|
|
152
|
+
const indexKey = `user:${userId}:subscriptions`;
|
|
153
|
+
const existing = await this.store.get(indexKey);
|
|
154
|
+
if (existing) {
|
|
155
|
+
const subscriptionIds = JSON.parse(existing);
|
|
156
|
+
const filtered = subscriptionIds.filter((id) => id !== subscriptionId);
|
|
157
|
+
await this.store.set(indexKey, JSON.stringify(filtered));
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Find resource definition for URI
|
|
162
|
+
*/
|
|
163
|
+
findResourceForUri(uri) {
|
|
164
|
+
return this.resources.find((resource) => {
|
|
165
|
+
// Convert URI template to regex pattern
|
|
166
|
+
// Step 1: Replace template variables with a placeholder
|
|
167
|
+
const withPlaceholders = resource.uri.replace(/\{[^}]+\}/g, '__PLACEHOLDER__');
|
|
168
|
+
// Step 2: Escape special regex characters (but not our placeholders)
|
|
169
|
+
const escapedPattern = withPlaceholders.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
170
|
+
// Step 3: Replace placeholders with capture groups
|
|
171
|
+
const patternString = escapedPattern.replace(/__PLACEHOLDER__/g, '([^/]+)');
|
|
172
|
+
// Step 4: Create regex with anchors
|
|
173
|
+
const pattern = new RegExp('^' + patternString + '$');
|
|
174
|
+
console.log('Pattern for resource', resource.name, ':', pattern);
|
|
175
|
+
console.log('Testing URI:', uri);
|
|
176
|
+
return pattern.test(uri);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
exports.SubscriptionManager = SubscriptionManager;
|
|
181
|
+
//# sourceMappingURL=SubscriptionManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SubscriptionManager.js","sourceRoot":"","sources":["../../src/subscriptions/SubscriptionManager.ts"],"names":[],"mappings":";;;AAAA,sCAA0D;AAQ1D,oCAAsE;AAEtE,MAAa,mBAAmB;IAC9B,YACU,KAAoB,EACpB,SAA+B,EAC/B,SAAiB,EACjB,MAAe;QAHf,UAAK,GAAL,KAAK,CAAe;QACpB,cAAS,GAAT,SAAS,CAAsB;QAC/B,cAAS,GAAT,SAAS,CAAQ;QACjB,WAAM,GAAN,MAAM,CAAS;IACtB,CAAC;IAEJ;;OAEG;IACH,KAAK,CAAC,kBAAkB,CAAC,MAKxB;QACC,MAAM,EAAE,GAAG,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;QAEzE,2BAA2B;QAC3B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,EAAE,QAAQ,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;YACjE,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC;YACjC,OAAO,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC3B,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AArOD,kDAqOC"}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { Request, Response, NextFunction } from 'express';
|
|
2
|
+
/**
|
|
3
|
+
* JSON Schema definition for input validation
|
|
4
|
+
*/
|
|
5
|
+
export interface JSONSchema {
|
|
6
|
+
type: string;
|
|
7
|
+
properties?: Record<string, any>;
|
|
8
|
+
required?: string[];
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Authentication context passed to handlers
|
|
13
|
+
*/
|
|
14
|
+
export interface AuthContext {
|
|
15
|
+
userId: string;
|
|
16
|
+
[key: string]: any;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Authentication handler function
|
|
20
|
+
*/
|
|
21
|
+
export type AuthenticateFunction = (req: Request) => Promise<AuthContext>;
|
|
22
|
+
/**
|
|
23
|
+
* Logger interface
|
|
24
|
+
*/
|
|
25
|
+
export interface Logger {
|
|
26
|
+
debug(message: string, meta?: any): void;
|
|
27
|
+
info(message: string, meta?: any): void;
|
|
28
|
+
warn(message: string, meta?: any): void;
|
|
29
|
+
error(message: string, meta?: any): void;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Key-value store interface for persistence
|
|
33
|
+
*/
|
|
34
|
+
export interface KeyValueStore {
|
|
35
|
+
/**
|
|
36
|
+
* Get value by key
|
|
37
|
+
* @returns Value as string, or null if not found
|
|
38
|
+
*/
|
|
39
|
+
get(key: string): Promise<string | null>;
|
|
40
|
+
/**
|
|
41
|
+
* Set value with optional TTL
|
|
42
|
+
* @param key - Key to set
|
|
43
|
+
* @param value - Value (will be JSON stringified)
|
|
44
|
+
* @param ttl - Time to live in seconds (optional)
|
|
45
|
+
*/
|
|
46
|
+
set(key: string, value: string, ttl?: number): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Delete key
|
|
49
|
+
*/
|
|
50
|
+
delete(key: string): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Scan keys by pattern (optional, for debugging)
|
|
53
|
+
* @param pattern - Glob pattern (e.g., "subscription:*")
|
|
54
|
+
*/
|
|
55
|
+
scan?(pattern: string): Promise<string[]>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Tool handler function
|
|
59
|
+
*/
|
|
60
|
+
export type ToolHandler<TInput = any, TOutput = any> = (input: TInput, context: AuthContext) => Promise<TOutput>;
|
|
61
|
+
/**
|
|
62
|
+
* Tool definition
|
|
63
|
+
*/
|
|
64
|
+
export interface ToolDefinition<TInput = any, TOutput = any> {
|
|
65
|
+
name: string;
|
|
66
|
+
description: string;
|
|
67
|
+
inputSchema: JSONSchema;
|
|
68
|
+
handler: ToolHandler<TInput, TOutput>;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Resource list item
|
|
72
|
+
*/
|
|
73
|
+
export interface ResourceListItem {
|
|
74
|
+
uri: string;
|
|
75
|
+
name: string;
|
|
76
|
+
description?: string;
|
|
77
|
+
mimeType?: string;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Resource read result
|
|
81
|
+
*/
|
|
82
|
+
export interface ResourceReadResult<TData = any> {
|
|
83
|
+
contents: TData;
|
|
84
|
+
metadata?: Record<string, any>;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Resource read options
|
|
88
|
+
*/
|
|
89
|
+
export interface ResourceReadOptions {
|
|
90
|
+
pagination?: {
|
|
91
|
+
page?: number;
|
|
92
|
+
limit?: number;
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Subscription metadata returned by onSubscribe
|
|
97
|
+
*/
|
|
98
|
+
export interface SubscriptionMetadata {
|
|
99
|
+
thirdPartyWebhookId: string;
|
|
100
|
+
metadata?: Record<string, any>;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Webhook change information
|
|
104
|
+
*/
|
|
105
|
+
export interface WebhookChangeInfo {
|
|
106
|
+
resourceUri: string;
|
|
107
|
+
changeType: 'created' | 'updated' | 'deleted';
|
|
108
|
+
data?: any;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Resource subscription handlers
|
|
112
|
+
*/
|
|
113
|
+
export interface ResourceSubscription {
|
|
114
|
+
/**
|
|
115
|
+
* Called when a client subscribes to a resource
|
|
116
|
+
*/
|
|
117
|
+
onSubscribe: (uri: string, subscriptionId: string, thirdPartyWebhookUrl: string, context: AuthContext) => Promise<SubscriptionMetadata>;
|
|
118
|
+
/**
|
|
119
|
+
* Called when a client unsubscribes
|
|
120
|
+
*/
|
|
121
|
+
onUnsubscribe: (uri: string, subscriptionId: string, storedData: SubscriptionMetadata, context: AuthContext) => Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* Called when third-party webhook is received
|
|
124
|
+
*/
|
|
125
|
+
onWebhook: (subscriptionId: string, payload: any, headers: Record<string, string>) => Promise<WebhookChangeInfo | null>;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Resource definition
|
|
129
|
+
*/
|
|
130
|
+
export interface ResourceDefinition<TData = any> {
|
|
131
|
+
uri: string;
|
|
132
|
+
name: string;
|
|
133
|
+
description: string;
|
|
134
|
+
mimeType?: string;
|
|
135
|
+
read: (uri: string, context: AuthContext, options?: ResourceReadOptions) => Promise<ResourceReadResult<TData>>;
|
|
136
|
+
list?: (context: AuthContext) => Promise<ResourceListItem[]>;
|
|
137
|
+
subscription?: ResourceSubscription;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Prompt definition
|
|
141
|
+
*/
|
|
142
|
+
export interface PromptDefinition {
|
|
143
|
+
name: string;
|
|
144
|
+
description: string;
|
|
145
|
+
arguments?: Array<{
|
|
146
|
+
name: string;
|
|
147
|
+
description: string;
|
|
148
|
+
required?: boolean;
|
|
149
|
+
}>;
|
|
150
|
+
handler: (args: Record<string, any>, context: AuthContext) => Promise<{
|
|
151
|
+
messages: Array<{
|
|
152
|
+
role: 'user' | 'assistant';
|
|
153
|
+
content: string;
|
|
154
|
+
}>;
|
|
155
|
+
}>;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Webhook configuration
|
|
159
|
+
*/
|
|
160
|
+
export interface WebhookConfig {
|
|
161
|
+
incomingPath?: string;
|
|
162
|
+
incomingSecret?: string;
|
|
163
|
+
verifyIncomingSignature?: (payload: any, signature: string, secret: string) => boolean;
|
|
164
|
+
outgoing?: {
|
|
165
|
+
timeout?: number;
|
|
166
|
+
retries?: number;
|
|
167
|
+
retryDelay?: number;
|
|
168
|
+
signPayload?: (payload: any, secret: string) => string;
|
|
169
|
+
onBeforeCall?: (url: string, payload: any) => void;
|
|
170
|
+
onAfterCall?: (url: string, response: any, error?: any) => void;
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Metrics configuration
|
|
175
|
+
*/
|
|
176
|
+
export interface MetricsConfig {
|
|
177
|
+
enabled: boolean;
|
|
178
|
+
registry?: any;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Tracing configuration
|
|
182
|
+
*/
|
|
183
|
+
export interface TracingConfig {
|
|
184
|
+
enabled: boolean;
|
|
185
|
+
serviceName?: string;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Batch configuration
|
|
189
|
+
*/
|
|
190
|
+
export interface BatchConfig {
|
|
191
|
+
maxBatchSize?: number;
|
|
192
|
+
batchTimeout?: number;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Cache configuration
|
|
196
|
+
*/
|
|
197
|
+
export interface CacheConfig {
|
|
198
|
+
enabled: boolean;
|
|
199
|
+
ttl?: number;
|
|
200
|
+
keyPrefix?: string;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Dead letter queue configuration
|
|
204
|
+
*/
|
|
205
|
+
export interface DeadLetterQueueConfig {
|
|
206
|
+
enabled: boolean;
|
|
207
|
+
store: KeyValueStore;
|
|
208
|
+
retention?: number;
|
|
209
|
+
maxRetries?: number;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Middleware function
|
|
213
|
+
*/
|
|
214
|
+
export type Middleware = (req: Request, res: Response, next: NextFunction) => void | Promise<void>;
|
|
215
|
+
/**
|
|
216
|
+
* MCP Server configuration
|
|
217
|
+
*/
|
|
218
|
+
export interface MCPServerConfig {
|
|
219
|
+
name: string;
|
|
220
|
+
version: string;
|
|
221
|
+
port?: number;
|
|
222
|
+
host?: string;
|
|
223
|
+
basePath?: string;
|
|
224
|
+
publicUrl: string;
|
|
225
|
+
authenticate?: AuthenticateFunction;
|
|
226
|
+
tools: ToolDefinition[];
|
|
227
|
+
resources: ResourceDefinition[];
|
|
228
|
+
prompts?: PromptDefinition[];
|
|
229
|
+
store: KeyValueStore;
|
|
230
|
+
webhooks?: WebhookConfig;
|
|
231
|
+
batch?: BatchConfig;
|
|
232
|
+
cache?: CacheConfig;
|
|
233
|
+
metrics?: MetricsConfig;
|
|
234
|
+
tracing?: TracingConfig;
|
|
235
|
+
middleware?: Middleware[];
|
|
236
|
+
logger?: Logger;
|
|
237
|
+
logLevel?: 'debug' | 'info' | 'warn' | 'error';
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Stored subscription data
|
|
241
|
+
*/
|
|
242
|
+
export interface StoredSubscription {
|
|
243
|
+
uri: string;
|
|
244
|
+
resourceType: string;
|
|
245
|
+
clientCallbackUrl: string;
|
|
246
|
+
clientCallbackSecret?: string;
|
|
247
|
+
userId: string;
|
|
248
|
+
thirdPartyWebhookId: string;
|
|
249
|
+
metadata?: any;
|
|
250
|
+
createdAt: number;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* MCP Error codes
|
|
254
|
+
*/
|
|
255
|
+
export declare enum MCPErrorCode {
|
|
256
|
+
AuthenticationError = -32001,
|
|
257
|
+
ValidationError = -32002,
|
|
258
|
+
ResourceNotFoundError = -32003,
|
|
259
|
+
ToolExecutionError = -32004,
|
|
260
|
+
WebhookError = -32005,
|
|
261
|
+
StorageError = -32006
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* MCP Server instance
|
|
265
|
+
*/
|
|
266
|
+
export interface MCPServer {
|
|
267
|
+
start(): Promise<void>;
|
|
268
|
+
stop(): Promise<void>;
|
|
269
|
+
getApp(): any;
|
|
270
|
+
}
|
|
271
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACjC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;AAE1E;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC;IACzC,IAAI,CAAC,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,SAAS;IACrB,YAAY,SAAS;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,MAAM,IAAI,GAAG,CAAC;CACf"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MCPErrorCode = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* MCP Error codes
|
|
6
|
+
*/
|
|
7
|
+
var MCPErrorCode;
|
|
8
|
+
(function (MCPErrorCode) {
|
|
9
|
+
MCPErrorCode[MCPErrorCode["AuthenticationError"] = -32001] = "AuthenticationError";
|
|
10
|
+
MCPErrorCode[MCPErrorCode["ValidationError"] = -32002] = "ValidationError";
|
|
11
|
+
MCPErrorCode[MCPErrorCode["ResourceNotFoundError"] = -32003] = "ResourceNotFoundError";
|
|
12
|
+
MCPErrorCode[MCPErrorCode["ToolExecutionError"] = -32004] = "ToolExecutionError";
|
|
13
|
+
MCPErrorCode[MCPErrorCode["WebhookError"] = -32005] = "WebhookError";
|
|
14
|
+
MCPErrorCode[MCPErrorCode["StorageError"] = -32006] = "StorageError";
|
|
15
|
+
})(MCPErrorCode || (exports.MCPErrorCode = MCPErrorCode = {}));
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;AAiUA;;GAEG;AACH,IAAY,YAOX;AAPD,WAAY,YAAY;IACtB,kFAA4B,CAAA;IAC5B,0EAAwB,CAAA;IACxB,sFAA8B,CAAA;IAC9B,gFAA2B,CAAA;IAC3B,oEAAqB,CAAA;IACrB,oEAAqB,CAAA;AACvB,CAAC,EAPW,YAAY,4BAAZ,YAAY,QAOvB"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate a unique subscription ID
|
|
3
|
+
*/
|
|
4
|
+
export declare function generateSubscriptionId(): string;
|
|
5
|
+
/**
|
|
6
|
+
* Generate webhook URL for third-party services
|
|
7
|
+
*/
|
|
8
|
+
export declare function generateWebhookUrl(publicUrl: string, subscriptionId: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Parse URI template
|
|
11
|
+
* Example: parseUriTemplate('github://repo/{owner}/{repo}', 'github://repo/octocat/hello')
|
|
12
|
+
* Returns: { owner: 'octocat', repo: 'hello' }
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseUriTemplate(template: string, uri: string): Record<string, string>;
|
|
15
|
+
/**
|
|
16
|
+
* Match URI against template
|
|
17
|
+
*/
|
|
18
|
+
export declare function matchUriTemplate(template: string, uri: string): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Create HMAC signature
|
|
21
|
+
*/
|
|
22
|
+
export declare function createHmacSignature(payload: any, secret: string, algorithm?: 'sha256' | 'sha1'): string;
|
|
23
|
+
/**
|
|
24
|
+
* Verify HMAC signature (timing-safe comparison)
|
|
25
|
+
*/
|
|
26
|
+
export declare function verifyHmacSignature(payload: any, signature: string, secret: string, algorithm?: 'sha256' | 'sha1'): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Sleep utility for retry delays
|
|
29
|
+
*/
|
|
30
|
+
export declare function sleep(ms: number): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Exponential backoff calculator
|
|
33
|
+
*/
|
|
34
|
+
export declare function calculateBackoff(attempt: number, baseDelay: number): number;
|
|
35
|
+
/**
|
|
36
|
+
* Sanitize URL for logging (remove sensitive query params)
|
|
37
|
+
*/
|
|
38
|
+
export declare function sanitizeUrl(url: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* Extract error message safely
|
|
41
|
+
*/
|
|
42
|
+
export declare function extractErrorMessage(error: unknown): string;
|
|
43
|
+
/**
|
|
44
|
+
* Validate URL format
|
|
45
|
+
*/
|
|
46
|
+
export declare function isValidUrl(url: string): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Validate HTTPS URL
|
|
49
|
+
*/
|
|
50
|
+
export declare function isHttpsUrl(url: string): boolean;
|
|
51
|
+
//# sourceMappingURL=index.d.ts.map
|