open-mcp-app 0.0.12 → 0.0.13
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/server/index.d.ts +2 -77
- package/dist/server/index.js +0 -304
- package/dist/server/index.js.map +1 -1
- package/package.json +1 -1
package/dist/server/index.d.ts
CHANGED
|
@@ -786,79 +786,6 @@ declare function htmlLoader(htmlOrPath: string, basePath?: string): () => string
|
|
|
786
786
|
*/
|
|
787
787
|
declare function wrapServer<T extends McpServer>(server: T): T;
|
|
788
788
|
|
|
789
|
-
/**
|
|
790
|
-
* Creature Runtime SDK (KV-only)
|
|
791
|
-
*
|
|
792
|
-
* Platform-specific app runtime client for hosted MCP apps running inside
|
|
793
|
-
* Creature sandboxes. This client intentionally supports KV only and uses
|
|
794
|
-
* app runtime REST endpoints with access/refresh token rotation.
|
|
795
|
-
*/
|
|
796
|
-
/**
|
|
797
|
-
* Result shape returned by client-side KV search.
|
|
798
|
-
*/
|
|
799
|
-
interface CreatureKvSearchResult {
|
|
800
|
-
key: string;
|
|
801
|
-
snippet?: string;
|
|
802
|
-
score?: number;
|
|
803
|
-
}
|
|
804
|
-
/**
|
|
805
|
-
* Runtime KV entry shape used by listWithValues operations.
|
|
806
|
-
*/
|
|
807
|
-
interface CreatureKvEntry {
|
|
808
|
-
key: string;
|
|
809
|
-
value: string;
|
|
810
|
-
}
|
|
811
|
-
/**
|
|
812
|
-
* Creature platform runtime SDK namespace.
|
|
813
|
-
*/
|
|
814
|
-
declare const creature: {
|
|
815
|
-
kv: {
|
|
816
|
-
/**
|
|
817
|
-
* Returns whether runtime KV is configured for this process.
|
|
818
|
-
*/
|
|
819
|
-
isAvailable: () => boolean;
|
|
820
|
-
/**
|
|
821
|
-
* Reads one KV value by key.
|
|
822
|
-
*/
|
|
823
|
-
get: ({ key, }: {
|
|
824
|
-
key: string;
|
|
825
|
-
}) => Promise<string | null>;
|
|
826
|
-
/**
|
|
827
|
-
* Writes one KV value.
|
|
828
|
-
*/
|
|
829
|
-
set: ({ key, value, }: {
|
|
830
|
-
key: string;
|
|
831
|
-
value: string;
|
|
832
|
-
}) => Promise<boolean>;
|
|
833
|
-
/**
|
|
834
|
-
* Deletes one KV key.
|
|
835
|
-
*/
|
|
836
|
-
delete: ({ key, }: {
|
|
837
|
-
key: string;
|
|
838
|
-
}) => Promise<boolean>;
|
|
839
|
-
/**
|
|
840
|
-
* Lists keys, optionally filtered by prefix.
|
|
841
|
-
*/
|
|
842
|
-
list: ({ prefix, }?: {
|
|
843
|
-
prefix?: string;
|
|
844
|
-
}) => Promise<string[]>;
|
|
845
|
-
/**
|
|
846
|
-
* Lists key/value entries, optionally filtered by prefix.
|
|
847
|
-
*/
|
|
848
|
-
listWithValues: ({ prefix, }?: {
|
|
849
|
-
prefix?: string;
|
|
850
|
-
}) => Promise<CreatureKvEntry[]>;
|
|
851
|
-
/**
|
|
852
|
-
* Performs a client-side text search across KV values.
|
|
853
|
-
*/
|
|
854
|
-
search: ({ query, prefix, limit, }: {
|
|
855
|
-
query: string;
|
|
856
|
-
prefix?: string;
|
|
857
|
-
limit?: number;
|
|
858
|
-
}) => Promise<CreatureKvSearchResult[]>;
|
|
859
|
-
};
|
|
860
|
-
};
|
|
861
|
-
|
|
862
789
|
/**
|
|
863
790
|
* Experimental Server APIs
|
|
864
791
|
*
|
|
@@ -1117,9 +1044,7 @@ declare function experimental_sampleMessage(params: CreateMessageRequestParams):
|
|
|
1117
1044
|
* import { exp } from "open-mcp-app/server";
|
|
1118
1045
|
*
|
|
1119
1046
|
* // Environment
|
|
1120
|
-
*
|
|
1121
|
-
* const dir = exp.getWritableDirectory();
|
|
1122
|
-
* }
|
|
1047
|
+
* const dir = exp.getWritableDirectory();
|
|
1123
1048
|
*
|
|
1124
1049
|
* // File I/O
|
|
1125
1050
|
* await exp.writeFile("config.json", JSON.stringify(config));
|
|
@@ -1147,4 +1072,4 @@ declare const exp: {
|
|
|
1147
1072
|
sampleMessage: typeof experimental_sampleMessage;
|
|
1148
1073
|
};
|
|
1149
1074
|
|
|
1150
|
-
export { App, type AppConfig, type
|
|
1075
|
+
export { App, type AppConfig, type DisplayMode, type IconConfig, type InstanceDestroyContext, MIME_TYPES, type ResourceConfig, type ServerLogLevel, type ServerLogger, type ToolAnnotations, type ToolCallInfo, type ToolCallResultInfo, type ToolConfig, type ToolContext, type ToolHandler, type ToolResult, type ToolVisibility, type TransportSessionInfo, type TransportType, type WebSocketConnection, createApp, exp, experimental_deleteFile, experimental_deleteFileSync, experimental_exists, experimental_existsSync, experimental_getProjectId, experimental_getServerName, experimental_getWritableDirectory, experimental_mkdir, experimental_mkdirSync, experimental_readFile, experimental_readFileSync, experimental_readdir, experimental_readdirSync, experimental_rmdir, experimental_rmdirSync, experimental_sampleMessage, experimental_writeFile, experimental_writeFileSync, htmlLoader, isHtmlContent, loadHtml, svgToDataUri, wrapServer };
|
package/dist/server/index.js
CHANGED
|
@@ -14729,309 +14729,6 @@ function wrapServer(server) {
|
|
|
14729
14729
|
return server;
|
|
14730
14730
|
}
|
|
14731
14731
|
|
|
14732
|
-
// src/server/creature.ts
|
|
14733
|
-
var DEFAULT_PAGE_LIMIT = 200;
|
|
14734
|
-
var CreatureRuntimeHttpError = class extends Error {
|
|
14735
|
-
status;
|
|
14736
|
-
body;
|
|
14737
|
-
/**
|
|
14738
|
-
* Creates a typed runtime HTTP error.
|
|
14739
|
-
*/
|
|
14740
|
-
constructor({
|
|
14741
|
-
status,
|
|
14742
|
-
message,
|
|
14743
|
-
body
|
|
14744
|
-
}) {
|
|
14745
|
-
super(message);
|
|
14746
|
-
this.status = status;
|
|
14747
|
-
this.body = body;
|
|
14748
|
-
}
|
|
14749
|
-
};
|
|
14750
|
-
var cachedAccessToken = null;
|
|
14751
|
-
var getApiBaseUrl = () => {
|
|
14752
|
-
const raw = process.env.CREATURE_API_BASE_URL?.trim();
|
|
14753
|
-
if (!raw) {
|
|
14754
|
-
return null;
|
|
14755
|
-
}
|
|
14756
|
-
return raw.replace(/\/+$/, "");
|
|
14757
|
-
};
|
|
14758
|
-
var getAccessToken = () => {
|
|
14759
|
-
if (cachedAccessToken && cachedAccessToken.length > 0) {
|
|
14760
|
-
return cachedAccessToken;
|
|
14761
|
-
}
|
|
14762
|
-
const envToken = process.env.CREATURE_APP_ACCESS_TOKEN?.trim();
|
|
14763
|
-
if (!envToken) {
|
|
14764
|
-
return null;
|
|
14765
|
-
}
|
|
14766
|
-
cachedAccessToken = envToken;
|
|
14767
|
-
return envToken;
|
|
14768
|
-
};
|
|
14769
|
-
var getRefreshToken = () => {
|
|
14770
|
-
const refreshToken = process.env.CREATURE_APP_REFRESH_TOKEN?.trim();
|
|
14771
|
-
return refreshToken && refreshToken.length > 0 ? refreshToken : null;
|
|
14772
|
-
};
|
|
14773
|
-
var setAccessToken = ({
|
|
14774
|
-
accessToken
|
|
14775
|
-
}) => {
|
|
14776
|
-
cachedAccessToken = accessToken;
|
|
14777
|
-
process.env.CREATURE_APP_ACCESS_TOKEN = accessToken;
|
|
14778
|
-
};
|
|
14779
|
-
var isRuntimeConfigured = () => {
|
|
14780
|
-
return !!(getApiBaseUrl() && getAccessToken() && getRefreshToken());
|
|
14781
|
-
};
|
|
14782
|
-
var buildRuntimeUrl = ({
|
|
14783
|
-
path: path4,
|
|
14784
|
-
query
|
|
14785
|
-
}) => {
|
|
14786
|
-
const baseUrl = getApiBaseUrl();
|
|
14787
|
-
if (!baseUrl) {
|
|
14788
|
-
throw new Error("Creature runtime API is not configured (CREATURE_API_BASE_URL is missing).");
|
|
14789
|
-
}
|
|
14790
|
-
const url = new URL(path4, `${baseUrl}/`);
|
|
14791
|
-
if (query) {
|
|
14792
|
-
for (const [key, value] of Object.entries(query)) {
|
|
14793
|
-
if (value === void 0) continue;
|
|
14794
|
-
url.searchParams.set(key, String(value));
|
|
14795
|
-
}
|
|
14796
|
-
}
|
|
14797
|
-
return url.toString();
|
|
14798
|
-
};
|
|
14799
|
-
var normalizeValueToString = ({
|
|
14800
|
-
value
|
|
14801
|
-
}) => {
|
|
14802
|
-
if (typeof value === "string") {
|
|
14803
|
-
return value;
|
|
14804
|
-
}
|
|
14805
|
-
return JSON.stringify(value);
|
|
14806
|
-
};
|
|
14807
|
-
var createSnippet = ({
|
|
14808
|
-
haystack,
|
|
14809
|
-
needle
|
|
14810
|
-
}) => {
|
|
14811
|
-
const lowerHaystack = haystack.toLowerCase();
|
|
14812
|
-
const lowerNeedle = needle.toLowerCase();
|
|
14813
|
-
const matchIndex = lowerHaystack.indexOf(lowerNeedle);
|
|
14814
|
-
if (matchIndex === -1) {
|
|
14815
|
-
return haystack.slice(0, 120);
|
|
14816
|
-
}
|
|
14817
|
-
const start = Math.max(0, matchIndex - 30);
|
|
14818
|
-
const end = Math.min(haystack.length, matchIndex + lowerNeedle.length + 30);
|
|
14819
|
-
const prefix = start > 0 ? "..." : "";
|
|
14820
|
-
const suffix = end < haystack.length ? "..." : "";
|
|
14821
|
-
return `${prefix}${haystack.slice(start, end)}${suffix}`;
|
|
14822
|
-
};
|
|
14823
|
-
var refreshAccessToken = async () => {
|
|
14824
|
-
const refreshToken = getRefreshToken();
|
|
14825
|
-
if (!refreshToken) {
|
|
14826
|
-
throw new Error("Creature runtime refresh token is missing.");
|
|
14827
|
-
}
|
|
14828
|
-
const response = await fetch(buildRuntimeUrl({ path: "/v1/app-runtime/token/refresh" }), {
|
|
14829
|
-
method: "POST",
|
|
14830
|
-
headers: {
|
|
14831
|
-
Authorization: `Bearer ${refreshToken}`
|
|
14832
|
-
}
|
|
14833
|
-
});
|
|
14834
|
-
let body = null;
|
|
14835
|
-
try {
|
|
14836
|
-
body = await response.json();
|
|
14837
|
-
} catch {
|
|
14838
|
-
body = null;
|
|
14839
|
-
}
|
|
14840
|
-
if (!response.ok || !body || typeof body !== "object") {
|
|
14841
|
-
throw new CreatureRuntimeHttpError({
|
|
14842
|
-
status: response.status,
|
|
14843
|
-
message: "Failed to refresh Creature runtime access token.",
|
|
14844
|
-
body
|
|
14845
|
-
});
|
|
14846
|
-
}
|
|
14847
|
-
const accessToken = body.access_token;
|
|
14848
|
-
if (typeof accessToken !== "string" || accessToken.length === 0) {
|
|
14849
|
-
throw new Error("Runtime refresh response did not include an access_token.");
|
|
14850
|
-
}
|
|
14851
|
-
setAccessToken({ accessToken });
|
|
14852
|
-
};
|
|
14853
|
-
var requestRuntime = async ({
|
|
14854
|
-
path: path4,
|
|
14855
|
-
method,
|
|
14856
|
-
body,
|
|
14857
|
-
allowRefresh = true,
|
|
14858
|
-
query
|
|
14859
|
-
}) => {
|
|
14860
|
-
const accessToken = getAccessToken();
|
|
14861
|
-
if (!accessToken) {
|
|
14862
|
-
throw new Error("Creature runtime access token is missing.");
|
|
14863
|
-
}
|
|
14864
|
-
const response = await fetch(buildRuntimeUrl({ path: path4, query }), {
|
|
14865
|
-
method,
|
|
14866
|
-
headers: {
|
|
14867
|
-
Authorization: `Bearer ${accessToken}`,
|
|
14868
|
-
...body !== void 0 ? { "Content-Type": "application/json" } : {}
|
|
14869
|
-
},
|
|
14870
|
-
...body !== void 0 ? { body: JSON.stringify(body) } : {}
|
|
14871
|
-
});
|
|
14872
|
-
if (response.status === 401 && allowRefresh) {
|
|
14873
|
-
await refreshAccessToken();
|
|
14874
|
-
return requestRuntime({
|
|
14875
|
-
path: path4,
|
|
14876
|
-
method,
|
|
14877
|
-
body,
|
|
14878
|
-
allowRefresh: false,
|
|
14879
|
-
query
|
|
14880
|
-
});
|
|
14881
|
-
}
|
|
14882
|
-
if (response.status === 204) {
|
|
14883
|
-
return void 0;
|
|
14884
|
-
}
|
|
14885
|
-
let parsedBody = null;
|
|
14886
|
-
try {
|
|
14887
|
-
parsedBody = await response.json();
|
|
14888
|
-
} catch {
|
|
14889
|
-
parsedBody = null;
|
|
14890
|
-
}
|
|
14891
|
-
if (!response.ok) {
|
|
14892
|
-
throw new CreatureRuntimeHttpError({
|
|
14893
|
-
status: response.status,
|
|
14894
|
-
message: `Creature runtime request failed (${response.status}).`,
|
|
14895
|
-
body: parsedBody
|
|
14896
|
-
});
|
|
14897
|
-
}
|
|
14898
|
-
return parsedBody;
|
|
14899
|
-
};
|
|
14900
|
-
var listKvEntries = async ({
|
|
14901
|
-
prefix
|
|
14902
|
-
}) => {
|
|
14903
|
-
const allEntries = [];
|
|
14904
|
-
let offset = 0;
|
|
14905
|
-
let total = Number.POSITIVE_INFINITY;
|
|
14906
|
-
while (offset < total) {
|
|
14907
|
-
const payload = await requestRuntime({
|
|
14908
|
-
path: "/v1/app-runtime/kv",
|
|
14909
|
-
method: "GET",
|
|
14910
|
-
query: {
|
|
14911
|
-
limit: DEFAULT_PAGE_LIMIT,
|
|
14912
|
-
offset
|
|
14913
|
-
}
|
|
14914
|
-
});
|
|
14915
|
-
const entries = Array.isArray(payload.entries) ? payload.entries : [];
|
|
14916
|
-
for (const entry of entries) {
|
|
14917
|
-
if (typeof entry.key !== "string") continue;
|
|
14918
|
-
if (prefix && !entry.key.startsWith(prefix)) continue;
|
|
14919
|
-
allEntries.push({
|
|
14920
|
-
key: entry.key,
|
|
14921
|
-
value: normalizeValueToString({ value: entry.value ?? null })
|
|
14922
|
-
});
|
|
14923
|
-
}
|
|
14924
|
-
const pageSize = entries.length;
|
|
14925
|
-
const nextTotal = payload.pagination?.total;
|
|
14926
|
-
total = typeof nextTotal === "number" ? nextTotal : offset + pageSize;
|
|
14927
|
-
if (pageSize === 0) break;
|
|
14928
|
-
offset += pageSize;
|
|
14929
|
-
}
|
|
14930
|
-
return allEntries;
|
|
14931
|
-
};
|
|
14932
|
-
var creature = {
|
|
14933
|
-
kv: {
|
|
14934
|
-
/**
|
|
14935
|
-
* Returns whether runtime KV is configured for this process.
|
|
14936
|
-
*/
|
|
14937
|
-
isAvailable: () => {
|
|
14938
|
-
return isRuntimeConfigured();
|
|
14939
|
-
},
|
|
14940
|
-
/**
|
|
14941
|
-
* Reads one KV value by key.
|
|
14942
|
-
*/
|
|
14943
|
-
get: async ({
|
|
14944
|
-
key
|
|
14945
|
-
}) => {
|
|
14946
|
-
try {
|
|
14947
|
-
const payload = await requestRuntime({
|
|
14948
|
-
path: `/v1/app-runtime/kv/${encodeURIComponent(key)}`,
|
|
14949
|
-
method: "GET"
|
|
14950
|
-
});
|
|
14951
|
-
if (!payload.entry) {
|
|
14952
|
-
return null;
|
|
14953
|
-
}
|
|
14954
|
-
return normalizeValueToString({ value: payload.entry.value ?? null });
|
|
14955
|
-
} catch (error) {
|
|
14956
|
-
if (error instanceof CreatureRuntimeHttpError && error.status === 404) {
|
|
14957
|
-
return null;
|
|
14958
|
-
}
|
|
14959
|
-
throw error;
|
|
14960
|
-
}
|
|
14961
|
-
},
|
|
14962
|
-
/**
|
|
14963
|
-
* Writes one KV value.
|
|
14964
|
-
*/
|
|
14965
|
-
set: async ({
|
|
14966
|
-
key,
|
|
14967
|
-
value
|
|
14968
|
-
}) => {
|
|
14969
|
-
await requestRuntime({
|
|
14970
|
-
path: `/v1/app-runtime/kv/${encodeURIComponent(key)}`,
|
|
14971
|
-
method: "PUT",
|
|
14972
|
-
body: { value }
|
|
14973
|
-
});
|
|
14974
|
-
return true;
|
|
14975
|
-
},
|
|
14976
|
-
/**
|
|
14977
|
-
* Deletes one KV key.
|
|
14978
|
-
*/
|
|
14979
|
-
delete: async ({
|
|
14980
|
-
key
|
|
14981
|
-
}) => {
|
|
14982
|
-
try {
|
|
14983
|
-
await requestRuntime({
|
|
14984
|
-
path: `/v1/app-runtime/kv/${encodeURIComponent(key)}`,
|
|
14985
|
-
method: "DELETE"
|
|
14986
|
-
});
|
|
14987
|
-
return true;
|
|
14988
|
-
} catch (error) {
|
|
14989
|
-
if (error instanceof CreatureRuntimeHttpError && error.status === 404) {
|
|
14990
|
-
return false;
|
|
14991
|
-
}
|
|
14992
|
-
throw error;
|
|
14993
|
-
}
|
|
14994
|
-
},
|
|
14995
|
-
/**
|
|
14996
|
-
* Lists keys, optionally filtered by prefix.
|
|
14997
|
-
*/
|
|
14998
|
-
list: async ({
|
|
14999
|
-
prefix
|
|
15000
|
-
} = {}) => {
|
|
15001
|
-
const entries = await listKvEntries({ prefix });
|
|
15002
|
-
return entries.map((entry) => entry.key);
|
|
15003
|
-
},
|
|
15004
|
-
/**
|
|
15005
|
-
* Lists key/value entries, optionally filtered by prefix.
|
|
15006
|
-
*/
|
|
15007
|
-
listWithValues: async ({
|
|
15008
|
-
prefix
|
|
15009
|
-
} = {}) => {
|
|
15010
|
-
return listKvEntries({ prefix });
|
|
15011
|
-
},
|
|
15012
|
-
/**
|
|
15013
|
-
* Performs a client-side text search across KV values.
|
|
15014
|
-
*/
|
|
15015
|
-
search: async ({
|
|
15016
|
-
query,
|
|
15017
|
-
prefix,
|
|
15018
|
-
limit
|
|
15019
|
-
}) => {
|
|
15020
|
-
const entries = await listKvEntries({ prefix });
|
|
15021
|
-
const normalizedQuery = query.toLowerCase();
|
|
15022
|
-
const matches = entries.filter((entry) => entry.value.toLowerCase().includes(normalizedQuery)).map((entry) => ({
|
|
15023
|
-
key: entry.key,
|
|
15024
|
-
snippet: createSnippet({ haystack: entry.value, needle: query }),
|
|
15025
|
-
score: 1
|
|
15026
|
-
}));
|
|
15027
|
-
if (typeof limit === "number" && limit > 0) {
|
|
15028
|
-
return matches.slice(0, limit);
|
|
15029
|
-
}
|
|
15030
|
-
return matches;
|
|
15031
|
-
}
|
|
15032
|
-
}
|
|
15033
|
-
};
|
|
15034
|
-
|
|
15035
14732
|
// src/server/experimental.ts
|
|
15036
14733
|
import fs2 from "fs";
|
|
15037
14734
|
import fsPromises from "fs/promises";
|
|
@@ -15192,7 +14889,6 @@ export {
|
|
|
15192
14889
|
App,
|
|
15193
14890
|
MIME_TYPES,
|
|
15194
14891
|
createApp,
|
|
15195
|
-
creature,
|
|
15196
14892
|
exp,
|
|
15197
14893
|
experimental_deleteFile,
|
|
15198
14894
|
experimental_deleteFileSync,
|