From 34eb2be5511228801e85d9c52ed5182a26aff12a Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Wed, 16 Jul 2025 10:18:13 -0700 Subject: [PATCH] sdk: use mcp for tool call --- sdk/package-lock.json | 4 +- sdk/package.json | 2 +- sdk/polyfill/level.js | 1 + sdk/types/package-lock.json | 4 +- sdk/types/package.json | 2 +- .../scrypted_python/scrypted_sdk/types.py | 17 ++++- sdk/types/src/build.ts | 1 + sdk/types/src/mcp.ts | 74 +++++++++++++++++++ sdk/types/src/types.input.ts | 5 +- 9 files changed, 101 insertions(+), 9 deletions(-) create mode 100644 sdk/polyfill/level.js create mode 100644 sdk/types/src/mcp.ts diff --git a/sdk/package-lock.json b/sdk/package-lock.json index 49a208270..1bca9e69d 100644 --- a/sdk/package-lock.json +++ b/sdk/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/sdk", - "version": "0.5.32", + "version": "0.5.33", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@scrypted/sdk", - "version": "0.5.32", + "version": "0.5.33", "license": "ISC", "dependencies": { "@babel/preset-typescript": "^7.27.1", diff --git a/sdk/package.json b/sdk/package.json index e50152741..e058672d6 100644 --- a/sdk/package.json +++ b/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/sdk", - "version": "0.5.32", + "version": "0.5.33", "description": "", "main": "dist/src/index.js", "exports": { diff --git a/sdk/polyfill/level.js b/sdk/polyfill/level.js new file mode 100644 index 000000000..12c23184e --- /dev/null +++ b/sdk/polyfill/level.js @@ -0,0 +1 @@ +const level = __non_webpack_require__('level'); module.exports = level; \ No newline at end of file diff --git a/sdk/types/package-lock.json b/sdk/types/package-lock.json index e3c255ec4..d89770eab 100644 --- a/sdk/types/package-lock.json +++ b/sdk/types/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/types", - "version": "0.5.30", + "version": "0.5.31", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/types", - "version": "0.5.30", + "version": "0.5.31", "license": "ISC", "dependencies": { "openai": "^5.3.0" diff --git a/sdk/types/package.json b/sdk/types/package.json index 6c64bb5a2..cfbc0ab2a 100644 --- a/sdk/types/package.json +++ b/sdk/types/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/types", - "version": "0.5.30", + "version": "0.5.31", "description": "", "main": "dist/index.js", "author": "", diff --git a/sdk/types/scrypted_python/scrypted_sdk/types.py b/sdk/types/scrypted_python/scrypted_sdk/types.py index 3533ed54b..3937f1737 100644 --- a/sdk/types/scrypted_python/scrypted_sdk/types.py +++ b/sdk/types/scrypted_python/scrypted_sdk/types.py @@ -449,6 +449,11 @@ class VideoStreamOptions(TypedDict): quality: float width: float +class ContentBlock(TypedDict): + + pass + + class MediaStreamDestination(TypedDict): pass @@ -491,6 +496,14 @@ class AudioVolumes(TypedDict): pass +class CallToolResult(TypedDict): + """https://modelcontextprotocol.io/specification/2025-06-18/schema#blobresourcecontents""" + + _meta: Any + content: list[ContentBlock] + isError: bool + structuredContent: Any + class ChatCompletionCapabilities(TypedDict): audio: bool @@ -1074,7 +1087,7 @@ class TamperState(TypedDict): pass -TYPES_VERSION = "0.5.30" +TYPES_VERSION = "0.5.31" class AirPurifier: @@ -1329,7 +1342,7 @@ class LauncherApplication: class LLMTools: - async def callLLMTool(self, name: str, parameters: Mapping[str, Any]) -> str: + async def callLLMTool(self, name: str, parameters: Mapping[str, Any]) -> CallToolResult: pass async def getLLMTools(self) -> list[ChatCompletionTool]: diff --git a/sdk/types/src/build.ts b/sdk/types/src/build.ts index f966e85f6..652a27c89 100644 --- a/sdk/types/src/build.ts +++ b/sdk/types/src/build.ts @@ -79,6 +79,7 @@ ${fs.readFileSync(path.join(__dirname, './types.input.ts'))} `; fs.writeFileSync(path.join(__dirname, '../gen/index.ts'), contents); +fs.copyFileSync(path.join(__dirname, './mcp.ts'), path.join(__dirname, '../gen/mcp.ts')); const discoveredTypes = new Set(); discoveredTypes.add('EventDetails'); diff --git a/sdk/types/src/mcp.ts b/sdk/types/src/mcp.ts new file mode 100644 index 000000000..9be28f370 --- /dev/null +++ b/sdk/types/src/mcp.ts @@ -0,0 +1,74 @@ +export interface BlobResourceContents { + _meta?: { [key: string]: unknown }; + blob: string; + mimeType?: string; + uri: string; +} + +export interface Annotations { + audience?: "user" | "assistant"; + lastModified?: string; + priority?: number; +} + +export interface TextResourceContents { + _meta?: { [key: string]: unknown }; + mimeType?: string; + text: string; + uri: string; +} + +export interface EmbeddedResource { + _meta?: { [key: string]: unknown }; + annotations?: Annotations; + resource: TextResourceContents | BlobResourceContents; + type: "resource"; +} + +export interface ResourceLink { + _meta?: { [key: string]: unknown }; + annotations?: Annotations; + description?: string; + mimeType?: string; + name: string; + size?: number; + title?: string; + type: "resource_link"; + uri: string; +} +export interface AudioContent { + _meta?: { [key: string]: unknown }; + annotations?: Annotations; + data: string; + mimeType: string; + type: "audio"; +} + +export interface ImageContent { + _meta?: { [key: string]: unknown }; + annotations?: Annotations; + data: string; + mimeType: string; + type: "image"; +} + +export interface TextContent { + _meta?: { [key: string]: unknown }; + annotations?: Annotations; + text: string; + type: "text"; +} + +export type ContentBlock = TextContent | ImageContent | AudioContent| ResourceLink | EmbeddedResource; + + +/** + * https://modelcontextprotocol.io/specification/2025-06-18/schema#blobresourcecontents + */ +export interface CallToolResult { + _meta?: { [key: string]: unknown }; + content: ContentBlock[]; + isError?: boolean; + structuredContent?: { [key: string]: unknown }; + [key: string]: unknown; +} diff --git a/sdk/types/src/types.input.ts b/sdk/types/src/types.input.ts index 267dc8eff..8ef3a2b7d 100644 --- a/sdk/types/src/types.input.ts +++ b/sdk/types/src/types.input.ts @@ -3,7 +3,9 @@ import type { Socket as NodeNetSocket } from 'net'; import type { ChatCompletionStreamParams } from 'openai/lib/ChatCompletionStream'; import type { ChatCompletionChunk, ChatCompletionCreateParamsNonStreaming, ChatCompletionMessageParam, ChatCompletion as ChatCompletionResponse, ChatCompletionTool } from 'openai/resources'; import type { Worker as NodeWorker } from 'worker_threads'; +import { CallToolResult } from './mcp'; export type { ChatCompletionChunk, ChatCompletionCreateParamsNonStreaming, ChatCompletionCreateParamsStreaming, ChatCompletionMessageParam, ChatCompletion as ChatCompletionResponse, ChatCompletionTool } from 'openai/resources'; +export type * from './mcp'; export type ScryptedNativeId = string | undefined; @@ -1066,9 +1068,10 @@ export interface PanTiltZoomCommand { preset?: string; } + export interface LLMTools { getLLMTools(): Promise; - callLLMTool(name: string, parameters: Record): Promise; + callLLMTool(name: string, parameters: Record): Promise; } export interface ChatCompletionCapabilities {