tiny-http-mcp-server 0.1.10 → 0.1.11
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/dist/composition.json
CHANGED
|
@@ -567,6 +567,7 @@ declare class HttpTransport implements McpTransport {
|
|
|
567
567
|
private cancelOpenSseReaders;
|
|
568
568
|
private fetchWithAbort;
|
|
569
569
|
private consumeWrittenLines;
|
|
570
|
+
private sendPost;
|
|
570
571
|
private createPostHeaders;
|
|
571
572
|
private createGetHeaders;
|
|
572
573
|
private createDeleteHeaders;
|
|
@@ -2919,6 +2919,9 @@ var HttpTransport = class {
|
|
|
2919
2919
|
this.openSseReaders.clear();
|
|
2920
2920
|
}
|
|
2921
2921
|
async fetchWithAbort(input, init) {
|
|
2922
|
+
if (this.disposed) {
|
|
2923
|
+
throw new Error("HTTP transport disposed");
|
|
2924
|
+
}
|
|
2922
2925
|
const abortController = new AbortController();
|
|
2923
2926
|
this.inFlightFetchAbortControllers.add(abortController);
|
|
2924
2927
|
try {
|
|
@@ -2935,25 +2938,44 @@ var HttpTransport = class {
|
|
|
2935
2938
|
if (this.disposed || line.length === 0) {
|
|
2936
2939
|
continue;
|
|
2937
2940
|
}
|
|
2938
|
-
const
|
|
2939
|
-
const
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
this.dispose(new Error("HTTP transport session expired (404 response)"));
|
|
2947
|
-
return;
|
|
2941
|
+
const parsed = parseJsonRpcMessage(line);
|
|
2942
|
+
const post = this.sendPost(line);
|
|
2943
|
+
if (parsed.type === "request" && parsed.message.method === "initialize" || parsed.type === "notification" && parsed.message.method === "notifications/initialized") {
|
|
2944
|
+
await post;
|
|
2945
|
+
} else {
|
|
2946
|
+
void post.catch((error) => {
|
|
2947
|
+
this.dispose(error instanceof Error ? error : new Error(String(error)));
|
|
2948
|
+
});
|
|
2948
2949
|
}
|
|
2949
|
-
await this.throwForPostHttpError(response);
|
|
2950
|
-
this.captureSessionId(response);
|
|
2951
|
-
this.maybeOpenGetSseStream();
|
|
2952
|
-
void this.forwardResponseMessages(response).catch((error) => {
|
|
2953
|
-
this.dispose(error instanceof Error ? error : new Error(String(error)));
|
|
2954
|
-
});
|
|
2955
2950
|
}
|
|
2956
2951
|
}
|
|
2952
|
+
async sendPost(line) {
|
|
2953
|
+
const hasSessionId = this.sessionId !== void 0;
|
|
2954
|
+
const response = await this.fetchWithOAuthRetry({
|
|
2955
|
+
method: "POST",
|
|
2956
|
+
createHeaders: () => this.createPostHeaders(),
|
|
2957
|
+
body: line
|
|
2958
|
+
});
|
|
2959
|
+
if (this.disposed) {
|
|
2960
|
+
await response.body?.cancel();
|
|
2961
|
+
return;
|
|
2962
|
+
}
|
|
2963
|
+
if (hasSessionId && response.status === 404) {
|
|
2964
|
+
this.sessionId = void 0;
|
|
2965
|
+
this.dispose(new Error("HTTP transport session expired (404 response)"));
|
|
2966
|
+
return;
|
|
2967
|
+
}
|
|
2968
|
+
await this.throwForPostHttpError(response);
|
|
2969
|
+
if (this.disposed) {
|
|
2970
|
+
await response.body?.cancel();
|
|
2971
|
+
return;
|
|
2972
|
+
}
|
|
2973
|
+
this.captureSessionId(response);
|
|
2974
|
+
this.maybeOpenGetSseStream();
|
|
2975
|
+
void this.forwardResponseMessages(response).catch((error) => {
|
|
2976
|
+
this.dispose(error instanceof Error ? error : new Error(String(error)));
|
|
2977
|
+
});
|
|
2978
|
+
}
|
|
2957
2979
|
async createPostHeaders() {
|
|
2958
2980
|
const headers = new Headers(this.headers);
|
|
2959
2981
|
headers.set("Accept", "application/json, text/event-stream");
|
|
@@ -3750,6 +3772,19 @@ function isJsonRpcErrorObject(value) {
|
|
|
3750
3772
|
}
|
|
3751
3773
|
return value.data === void 0 || hasOwn(value, "data");
|
|
3752
3774
|
}
|
|
3775
|
+
function parseJsonRpcMessage(line) {
|
|
3776
|
+
let parsed;
|
|
3777
|
+
try {
|
|
3778
|
+
parsed = JSON.parse(line);
|
|
3779
|
+
} catch {
|
|
3780
|
+
return {
|
|
3781
|
+
type: "invalid",
|
|
3782
|
+
id: null,
|
|
3783
|
+
error: parseError()
|
|
3784
|
+
};
|
|
3785
|
+
}
|
|
3786
|
+
return parseJsonRpcPayload(parsed);
|
|
3787
|
+
}
|
|
3753
3788
|
function parseJsonRpcPayload(parsed) {
|
|
3754
3789
|
if (!isObjectRecord5(parsed)) {
|
|
3755
3790
|
return {
|