diff --git a/src/ts/process/mcp.ts b/src/ts/process/mcp.ts new file mode 100644 index 00000000..e3a67687 --- /dev/null +++ b/src/ts/process/mcp.ts @@ -0,0 +1,135 @@ +import { v4 } from "uuid" +import { fetchNative } from "../globalApi.svelte" +import { DBState } from "../stores.svelte"; +import { message } from "@tauri-apps/plugin-dialog"; + +type MCPPrompt = { + name: string; // Unique identifier for the prompt + description?: string; // Human-readable description + arguments?:{ // Optional list of arguments + name: string; // Argument identifier + description?: string; // Argument description + required?: boolean; // Whether argument is required + }[] + url?:string +} + +type RPCRequestResult = { + jsonrpc: "2.0", + id: number | string, + result?: any, + error?: { + code: number, + message: string, + data?: any + } +} + +let requestId = '' + +async function MPCClientRequest(url:string|null, method:string, params?:any):Promise{ + + const body = { + jsonrpc: "2.0", + id: requestId, + method: method, + params: params + } + + if(!params){ + delete body.params + } + + try { + + const response = await fetchNative(url, { + body: JSON.stringify(body), + method: "POST" + }) + const d:RPCRequestResult = await response.json() + return d + } catch (error) { + return { + jsonrpc: "2.0", + id: requestId, + error: { + code: 400, + message: "None" + } + } + } +} + +async function getMCPPromptList(){ + let prompts:MCPPrompt[] = [] + for(let i=0;i