@iqai/adk 0.0.9 → 0.0.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/CHANGELOG.md +12 -0
- package/dist/index.d.mts +99 -41
- package/dist/index.d.ts +99 -41
- package/dist/index.js +195 -138
- package/dist/index.mjs +117 -60
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @iqai/adk
|
|
2
2
|
|
|
3
|
+
## 0.0.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 9c7a7a7: Adds proper input and output conversion from LLMRequest and LLMResponse types
|
|
8
|
+
|
|
9
|
+
## 0.0.10
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- cb16b0c: Adds helper functions for creating sampling handlers
|
|
14
|
+
|
|
3
15
|
## 0.0.9
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -2699,6 +2699,11 @@ type McpConfig = {
|
|
|
2699
2699
|
maxSize?: number;
|
|
2700
2700
|
};
|
|
2701
2701
|
debug?: boolean;
|
|
2702
|
+
/**
|
|
2703
|
+
* Sampling handler for processing MCP sampling requests.
|
|
2704
|
+
* This allows MCP servers to request LLM completions through your ADK agent.
|
|
2705
|
+
*/
|
|
2706
|
+
samplingHandler?: SamplingHandler;
|
|
2702
2707
|
};
|
|
2703
2708
|
type McpTransportType = {
|
|
2704
2709
|
mode: "stdio";
|
|
@@ -2730,41 +2735,9 @@ declare class McpError extends Error {
|
|
|
2730
2735
|
originalError?: Error;
|
|
2731
2736
|
constructor(message: string, type: McpErrorType, originalError?: Error);
|
|
2732
2737
|
}
|
|
2733
|
-
type
|
|
2734
|
-
type
|
|
2735
|
-
|
|
2736
|
-
/**
|
|
2737
|
-
* ADK sampling request format - what we pass to the user's handler
|
|
2738
|
-
*/
|
|
2739
|
-
interface ADKSamplingRequest {
|
|
2740
|
-
messages: Message[];
|
|
2741
|
-
systemPrompt?: string;
|
|
2742
|
-
modelPreferences?: {
|
|
2743
|
-
hints?: Array<{
|
|
2744
|
-
name?: string;
|
|
2745
|
-
}>;
|
|
2746
|
-
costPriority?: number;
|
|
2747
|
-
speedPriority?: number;
|
|
2748
|
-
intelligencePriority?: number;
|
|
2749
|
-
};
|
|
2750
|
-
includeContext?: "none" | "thisServer" | "allServers";
|
|
2751
|
-
temperature?: number;
|
|
2752
|
-
maxTokens: number;
|
|
2753
|
-
stopSequences?: string[];
|
|
2754
|
-
metadata?: Record<string, unknown>;
|
|
2755
|
-
}
|
|
2756
|
-
/**
|
|
2757
|
-
* ADK sampling response format - what we expect from the user's handler
|
|
2758
|
-
*/
|
|
2759
|
-
interface ADKSamplingResponse {
|
|
2760
|
-
model: string;
|
|
2761
|
-
stopReason?: "endTurn" | "stopSequence" | "maxTokens" | string;
|
|
2762
|
-
content: string | null;
|
|
2763
|
-
}
|
|
2764
|
-
/**
|
|
2765
|
-
* ADK sampling handler function type - receives ADK formatted messages
|
|
2766
|
-
*/
|
|
2767
|
-
type ADKSamplingHandler = (request: ADKSamplingRequest) => Promise<ADKSamplingResponse>;
|
|
2738
|
+
type McpSamplingRequest = z.infer<typeof CreateMessageRequestSchema>;
|
|
2739
|
+
type McpSamplingResponse = z.infer<typeof CreateMessageResultSchema>;
|
|
2740
|
+
type SamplingHandler = (messages: LLMRequest) => LLMResponse;
|
|
2768
2741
|
|
|
2769
2742
|
declare class McpClientService {
|
|
2770
2743
|
private config;
|
|
@@ -2809,9 +2782,9 @@ declare class McpClientService {
|
|
|
2809
2782
|
isConnected(): boolean;
|
|
2810
2783
|
private setupSamplingHandler;
|
|
2811
2784
|
/**
|
|
2812
|
-
* Set
|
|
2785
|
+
* Set a new ADK sampling handler
|
|
2813
2786
|
*/
|
|
2814
|
-
setSamplingHandler(handler:
|
|
2787
|
+
setSamplingHandler(handler: SamplingHandler): void;
|
|
2815
2788
|
/**
|
|
2816
2789
|
* Remove the sampling handler
|
|
2817
2790
|
*/
|
|
@@ -2838,6 +2811,76 @@ declare function normalizeJsonSchema(schema: Record<string, any>): JSONSchema;
|
|
|
2838
2811
|
*/
|
|
2839
2812
|
declare function mcpSchemaToParameters(mcpTool: Tool): JSONSchema;
|
|
2840
2813
|
|
|
2814
|
+
/**
|
|
2815
|
+
* MCP Sampling Handler class that handles message format conversion
|
|
2816
|
+
* between MCP format and ADK format
|
|
2817
|
+
*/
|
|
2818
|
+
declare class McpSamplingHandler {
|
|
2819
|
+
private logger;
|
|
2820
|
+
private samplingHandler;
|
|
2821
|
+
constructor(samplingHandler: SamplingHandler);
|
|
2822
|
+
/**
|
|
2823
|
+
* Handle MCP sampling request and convert between formats
|
|
2824
|
+
*/
|
|
2825
|
+
handleSamplingRequest(request: McpSamplingRequest): Promise<McpSamplingResponse>;
|
|
2826
|
+
/**
|
|
2827
|
+
* Convert MCP messages to ADK message format
|
|
2828
|
+
*/
|
|
2829
|
+
private convertMcpMessagesToADK;
|
|
2830
|
+
/**
|
|
2831
|
+
* Convert a single MCP message to ADK message format
|
|
2832
|
+
*/
|
|
2833
|
+
private convertSingleMcpMessageToADK;
|
|
2834
|
+
/**
|
|
2835
|
+
* Convert MCP message content to ADK content format
|
|
2836
|
+
*/
|
|
2837
|
+
private convertMcpContentToADK;
|
|
2838
|
+
/**
|
|
2839
|
+
* Convert ADK response to MCP response format
|
|
2840
|
+
*/
|
|
2841
|
+
private convertADKResponseToMcp;
|
|
2842
|
+
/**
|
|
2843
|
+
* Update the ADK handler
|
|
2844
|
+
*/
|
|
2845
|
+
updateHandler(handler: SamplingHandler): void;
|
|
2846
|
+
}
|
|
2847
|
+
/**
|
|
2848
|
+
* Helper function to create a sampling handler with proper TypeScript types.
|
|
2849
|
+
*
|
|
2850
|
+
* @param handler - Function that handles sampling requests
|
|
2851
|
+
* @returns Properly typed ADK sampling handler
|
|
2852
|
+
*
|
|
2853
|
+
* @example
|
|
2854
|
+
* ```typescript
|
|
2855
|
+
* import { createSamplingHandler, GoogleLLM, LLMRequest } from "@iqai/adk";
|
|
2856
|
+
*
|
|
2857
|
+
* const llm = new GoogleLLM("gemini-2.5-flash-preview-05-20");
|
|
2858
|
+
*
|
|
2859
|
+
* const samplingHandler = createSamplingHandler(async (request) => {
|
|
2860
|
+
* // request is properly typed with all the fields
|
|
2861
|
+
* const llmRequest = new LLMRequest({
|
|
2862
|
+
* messages: request.messages,
|
|
2863
|
+
* config: {
|
|
2864
|
+
* temperature: request.temperature || 0.7,
|
|
2865
|
+
* max_tokens: request.maxTokens,
|
|
2866
|
+
* }
|
|
2867
|
+
* });
|
|
2868
|
+
*
|
|
2869
|
+
* const responses = [];
|
|
2870
|
+
* for await (const response of llm.generateContentAsync(llmRequest)) {
|
|
2871
|
+
* responses.push(response);
|
|
2872
|
+
* }
|
|
2873
|
+
*
|
|
2874
|
+
* return {
|
|
2875
|
+
* model: llm.model,
|
|
2876
|
+
* content: responses[responses.length - 1].content,
|
|
2877
|
+
* stopReason: "endTurn"
|
|
2878
|
+
* };
|
|
2879
|
+
* });
|
|
2880
|
+
* ```
|
|
2881
|
+
*/
|
|
2882
|
+
declare function createSamplingHandler(handler: SamplingHandler): SamplingHandler;
|
|
2883
|
+
|
|
2841
2884
|
/**
|
|
2842
2885
|
* A class for managing MCP tools similar to Python's MCPToolset.
|
|
2843
2886
|
* Provides functionality to retrieve and use tools from an MCP server.
|
|
@@ -2858,6 +2901,17 @@ declare class McpToolset {
|
|
|
2858
2901
|
* Initializes the client service and establishes a connection.
|
|
2859
2902
|
*/
|
|
2860
2903
|
initialize(): Promise<McpClientService>;
|
|
2904
|
+
/**
|
|
2905
|
+
* Set a sampling handler for this MCP toolset.
|
|
2906
|
+
* This allows MCP servers to request LLM completions through your ADK agent.
|
|
2907
|
+
*
|
|
2908
|
+
* @param handler - ADK sampling handler that receives ADK-formatted messages
|
|
2909
|
+
*/
|
|
2910
|
+
setSamplingHandler(handler: SamplingHandler): void;
|
|
2911
|
+
/**
|
|
2912
|
+
* Remove the sampling handler
|
|
2913
|
+
*/
|
|
2914
|
+
removeSamplingHandler(): void;
|
|
2861
2915
|
/**
|
|
2862
2916
|
* Retrieves tools from the MCP server and converts them to BaseTool instances.
|
|
2863
2917
|
* Similar to Python's get_tools method.
|
|
@@ -2920,11 +2974,14 @@ type index$2_McpError = McpError;
|
|
|
2920
2974
|
declare const index$2_McpError: typeof McpError;
|
|
2921
2975
|
type index$2_McpErrorType = McpErrorType;
|
|
2922
2976
|
declare const index$2_McpErrorType: typeof McpErrorType;
|
|
2977
|
+
type index$2_McpSamplingHandler = McpSamplingHandler;
|
|
2978
|
+
declare const index$2_McpSamplingHandler: typeof McpSamplingHandler;
|
|
2979
|
+
type index$2_McpSamplingRequest = McpSamplingRequest;
|
|
2980
|
+
type index$2_McpSamplingResponse = McpSamplingResponse;
|
|
2923
2981
|
type index$2_McpToolset = McpToolset;
|
|
2924
2982
|
declare const index$2_McpToolset: typeof McpToolset;
|
|
2925
2983
|
type index$2_McpTransportType = McpTransportType;
|
|
2926
|
-
type index$
|
|
2927
|
-
type index$2_SamplingResponse = SamplingResponse;
|
|
2984
|
+
type index$2_SamplingHandler = SamplingHandler;
|
|
2928
2985
|
type index$2_ToolConfig = ToolConfig;
|
|
2929
2986
|
type index$2_ToolContext = ToolContext;
|
|
2930
2987
|
declare const index$2_ToolContext: typeof ToolContext;
|
|
@@ -2935,12 +2992,13 @@ declare const index$2_UserInteractionTool: typeof UserInteractionTool;
|
|
|
2935
2992
|
declare const index$2_adkToMcpToolType: typeof adkToMcpToolType;
|
|
2936
2993
|
declare const index$2_buildFunctionDeclaration: typeof buildFunctionDeclaration;
|
|
2937
2994
|
declare const index$2_createFunctionTool: typeof createFunctionTool;
|
|
2995
|
+
declare const index$2_createSamplingHandler: typeof createSamplingHandler;
|
|
2938
2996
|
declare const index$2_getMcpTools: typeof getMcpTools;
|
|
2939
2997
|
declare const index$2_jsonSchemaToDeclaration: typeof jsonSchemaToDeclaration;
|
|
2940
2998
|
declare const index$2_mcpSchemaToParameters: typeof mcpSchemaToParameters;
|
|
2941
2999
|
declare const index$2_normalizeJsonSchema: typeof normalizeJsonSchema;
|
|
2942
3000
|
declare namespace index$2 {
|
|
2943
|
-
export { index$2_BaseTool as BaseTool, type index$2_BuildFunctionDeclarationOptions as BuildFunctionDeclarationOptions, index$2_ExitLoopTool as ExitLoopTool, index$2_FileOperationsTool as FileOperationsTool, index$2_FunctionTool as FunctionTool, index$2_GetUserChoiceTool as GetUserChoiceTool, index$2_GoogleSearch as GoogleSearch, index$2_HttpRequestTool as HttpRequestTool, type index$2_IToolContext as IToolContext, index$2_LoadMemoryTool as LoadMemoryTool, type index$2_McpConfig as McpConfig, index$2_McpError as McpError, index$2_McpErrorType as McpErrorType, index$
|
|
3001
|
+
export { index$2_BaseTool as BaseTool, type index$2_BuildFunctionDeclarationOptions as BuildFunctionDeclarationOptions, index$2_ExitLoopTool as ExitLoopTool, index$2_FileOperationsTool as FileOperationsTool, index$2_FunctionTool as FunctionTool, index$2_GetUserChoiceTool as GetUserChoiceTool, index$2_GoogleSearch as GoogleSearch, index$2_HttpRequestTool as HttpRequestTool, type index$2_IToolContext as IToolContext, index$2_LoadMemoryTool as LoadMemoryTool, type index$2_McpConfig as McpConfig, index$2_McpError as McpError, index$2_McpErrorType as McpErrorType, index$2_McpSamplingHandler as McpSamplingHandler, type index$2_McpSamplingRequest as McpSamplingRequest, type index$2_McpSamplingResponse as McpSamplingResponse, index$2_McpToolset as McpToolset, type index$2_McpTransportType as McpTransportType, type index$2_SamplingHandler as SamplingHandler, type index$2_ToolConfig as ToolConfig, index$2_ToolContext as ToolContext, index$2_TransferToAgentTool as TransferToAgentTool, index$2_UserInteractionTool as UserInteractionTool, index$2_adkToMcpToolType as adkToMcpToolType, index$2_buildFunctionDeclaration as buildFunctionDeclaration, index$2_createFunctionTool as createFunctionTool, index$2_createSamplingHandler as createSamplingHandler, index$2_getMcpTools as getMcpTools, index$2_jsonSchemaToDeclaration as jsonSchemaToDeclaration, index$2_mcpSchemaToParameters as mcpSchemaToParameters, index$2_normalizeJsonSchema as normalizeJsonSchema };
|
|
2944
3002
|
}
|
|
2945
3003
|
|
|
2946
3004
|
/**
|
|
@@ -3499,4 +3557,4 @@ declare class InMemoryRunner extends Runner {
|
|
|
3499
3557
|
|
|
3500
3558
|
declare const VERSION = "0.1.0";
|
|
3501
3559
|
|
|
3502
|
-
export { Agent, type AgentConfig, index$3 as Agents, AnthropicLLM, type AnthropicLLMConfig, AnthropicLLMConnection, ApiKeyCredential, ApiKeyScheme, type AudioTranscriptionConfig, AuthConfig, AuthCredential, AuthCredentialType, AuthHandler, AuthScheme, AuthSchemeType, BaseAgent, BaseLLM, BaseLLMConnection, type BaseMemoryService, BaseTool, BasicAuthCredential, BearerTokenCredential, type BuildFunctionDeclarationOptions, ExitLoopTool, FileOperationsTool, type FunctionCall, type FunctionDeclaration, FunctionTool, GetUserChoiceTool, GoogleLLM, type GoogleLLMConfig, GoogleSearch, HttpRequestTool, HttpScheme, type IToolContext, type ImageContent, InMemoryMemoryService, InMemoryRunner, InMemorySessionService, InvocationContext, type JSONSchema, LLMRegistry, LLMRequest, type LLMRequestConfig, LLMResponse, LangGraphAgent, type LangGraphAgentConfig, type LangGraphNode, type ListSessionOptions, LoadMemoryTool, LoopAgent, type LoopAgentConfig, type McpConfig, McpError, McpErrorType, McpToolset, type McpTransportType, index$1 as Memory, type MemoryResult, type Message, type MessageContent, type MessageRole, index$4 as Models, OAuth2Credential, OAuth2Scheme, type OAuthFlow, type OAuthFlows, OpenAILLM, type OpenAILLMConfig, OpenAILLMConnection, OpenIdConnectScheme, ParallelAgent, type ParallelAgentConfig, PersistentMemoryService, PgLiteSessionService, PostgresSessionService, RunConfig, Runner, type
|
|
3560
|
+
export { Agent, type AgentConfig, index$3 as Agents, AnthropicLLM, type AnthropicLLMConfig, AnthropicLLMConnection, ApiKeyCredential, ApiKeyScheme, type AudioTranscriptionConfig, AuthConfig, AuthCredential, AuthCredentialType, AuthHandler, AuthScheme, AuthSchemeType, BaseAgent, BaseLLM, BaseLLMConnection, type BaseMemoryService, BaseTool, BasicAuthCredential, BearerTokenCredential, type BuildFunctionDeclarationOptions, ExitLoopTool, FileOperationsTool, type FunctionCall, type FunctionDeclaration, FunctionTool, GetUserChoiceTool, GoogleLLM, type GoogleLLMConfig, GoogleSearch, HttpRequestTool, HttpScheme, type IToolContext, type ImageContent, InMemoryMemoryService, InMemoryRunner, InMemorySessionService, InvocationContext, type JSONSchema, LLMRegistry, LLMRequest, type LLMRequestConfig, LLMResponse, LangGraphAgent, type LangGraphAgentConfig, type LangGraphNode, type ListSessionOptions, LoadMemoryTool, LoopAgent, type LoopAgentConfig, type McpConfig, McpError, McpErrorType, McpSamplingHandler, type McpSamplingRequest, type McpSamplingResponse, McpToolset, type McpTransportType, index$1 as Memory, type MemoryResult, type Message, type MessageContent, type MessageRole, index$4 as Models, OAuth2Credential, OAuth2Scheme, type OAuthFlow, type OAuthFlows, OpenAILLM, type OpenAILLMConfig, OpenAILLMConnection, OpenIdConnectScheme, ParallelAgent, type ParallelAgentConfig, PersistentMemoryService, PgLiteSessionService, PostgresSessionService, RunConfig, Runner, type SamplingHandler, type SearchMemoryOptions, type SearchMemoryResponse, SequentialAgent, type SequentialAgentConfig, type Session, type SessionService, SessionState, index as Sessions, type SpeechConfig, SqliteSessionService, StreamingMode, type TextContent, type ToolCall, type ToolConfig, ToolContext, index$2 as Tools, TransferToAgentTool, UserInteractionTool, VERSION, adkToMcpToolType, buildFunctionDeclaration, cloneSession, createFunctionTool, createSamplingHandler, generateSessionId, getMcpTools, jsonSchemaToDeclaration, mcpSchemaToParameters, normalizeJsonSchema, registerProviders, validateSession };
|
package/dist/index.d.ts
CHANGED
|
@@ -2699,6 +2699,11 @@ type McpConfig = {
|
|
|
2699
2699
|
maxSize?: number;
|
|
2700
2700
|
};
|
|
2701
2701
|
debug?: boolean;
|
|
2702
|
+
/**
|
|
2703
|
+
* Sampling handler for processing MCP sampling requests.
|
|
2704
|
+
* This allows MCP servers to request LLM completions through your ADK agent.
|
|
2705
|
+
*/
|
|
2706
|
+
samplingHandler?: SamplingHandler;
|
|
2702
2707
|
};
|
|
2703
2708
|
type McpTransportType = {
|
|
2704
2709
|
mode: "stdio";
|
|
@@ -2730,41 +2735,9 @@ declare class McpError extends Error {
|
|
|
2730
2735
|
originalError?: Error;
|
|
2731
2736
|
constructor(message: string, type: McpErrorType, originalError?: Error);
|
|
2732
2737
|
}
|
|
2733
|
-
type
|
|
2734
|
-
type
|
|
2735
|
-
|
|
2736
|
-
/**
|
|
2737
|
-
* ADK sampling request format - what we pass to the user's handler
|
|
2738
|
-
*/
|
|
2739
|
-
interface ADKSamplingRequest {
|
|
2740
|
-
messages: Message[];
|
|
2741
|
-
systemPrompt?: string;
|
|
2742
|
-
modelPreferences?: {
|
|
2743
|
-
hints?: Array<{
|
|
2744
|
-
name?: string;
|
|
2745
|
-
}>;
|
|
2746
|
-
costPriority?: number;
|
|
2747
|
-
speedPriority?: number;
|
|
2748
|
-
intelligencePriority?: number;
|
|
2749
|
-
};
|
|
2750
|
-
includeContext?: "none" | "thisServer" | "allServers";
|
|
2751
|
-
temperature?: number;
|
|
2752
|
-
maxTokens: number;
|
|
2753
|
-
stopSequences?: string[];
|
|
2754
|
-
metadata?: Record<string, unknown>;
|
|
2755
|
-
}
|
|
2756
|
-
/**
|
|
2757
|
-
* ADK sampling response format - what we expect from the user's handler
|
|
2758
|
-
*/
|
|
2759
|
-
interface ADKSamplingResponse {
|
|
2760
|
-
model: string;
|
|
2761
|
-
stopReason?: "endTurn" | "stopSequence" | "maxTokens" | string;
|
|
2762
|
-
content: string | null;
|
|
2763
|
-
}
|
|
2764
|
-
/**
|
|
2765
|
-
* ADK sampling handler function type - receives ADK formatted messages
|
|
2766
|
-
*/
|
|
2767
|
-
type ADKSamplingHandler = (request: ADKSamplingRequest) => Promise<ADKSamplingResponse>;
|
|
2738
|
+
type McpSamplingRequest = z.infer<typeof CreateMessageRequestSchema>;
|
|
2739
|
+
type McpSamplingResponse = z.infer<typeof CreateMessageResultSchema>;
|
|
2740
|
+
type SamplingHandler = (messages: LLMRequest) => LLMResponse;
|
|
2768
2741
|
|
|
2769
2742
|
declare class McpClientService {
|
|
2770
2743
|
private config;
|
|
@@ -2809,9 +2782,9 @@ declare class McpClientService {
|
|
|
2809
2782
|
isConnected(): boolean;
|
|
2810
2783
|
private setupSamplingHandler;
|
|
2811
2784
|
/**
|
|
2812
|
-
* Set
|
|
2785
|
+
* Set a new ADK sampling handler
|
|
2813
2786
|
*/
|
|
2814
|
-
setSamplingHandler(handler:
|
|
2787
|
+
setSamplingHandler(handler: SamplingHandler): void;
|
|
2815
2788
|
/**
|
|
2816
2789
|
* Remove the sampling handler
|
|
2817
2790
|
*/
|
|
@@ -2838,6 +2811,76 @@ declare function normalizeJsonSchema(schema: Record<string, any>): JSONSchema;
|
|
|
2838
2811
|
*/
|
|
2839
2812
|
declare function mcpSchemaToParameters(mcpTool: Tool): JSONSchema;
|
|
2840
2813
|
|
|
2814
|
+
/**
|
|
2815
|
+
* MCP Sampling Handler class that handles message format conversion
|
|
2816
|
+
* between MCP format and ADK format
|
|
2817
|
+
*/
|
|
2818
|
+
declare class McpSamplingHandler {
|
|
2819
|
+
private logger;
|
|
2820
|
+
private samplingHandler;
|
|
2821
|
+
constructor(samplingHandler: SamplingHandler);
|
|
2822
|
+
/**
|
|
2823
|
+
* Handle MCP sampling request and convert between formats
|
|
2824
|
+
*/
|
|
2825
|
+
handleSamplingRequest(request: McpSamplingRequest): Promise<McpSamplingResponse>;
|
|
2826
|
+
/**
|
|
2827
|
+
* Convert MCP messages to ADK message format
|
|
2828
|
+
*/
|
|
2829
|
+
private convertMcpMessagesToADK;
|
|
2830
|
+
/**
|
|
2831
|
+
* Convert a single MCP message to ADK message format
|
|
2832
|
+
*/
|
|
2833
|
+
private convertSingleMcpMessageToADK;
|
|
2834
|
+
/**
|
|
2835
|
+
* Convert MCP message content to ADK content format
|
|
2836
|
+
*/
|
|
2837
|
+
private convertMcpContentToADK;
|
|
2838
|
+
/**
|
|
2839
|
+
* Convert ADK response to MCP response format
|
|
2840
|
+
*/
|
|
2841
|
+
private convertADKResponseToMcp;
|
|
2842
|
+
/**
|
|
2843
|
+
* Update the ADK handler
|
|
2844
|
+
*/
|
|
2845
|
+
updateHandler(handler: SamplingHandler): void;
|
|
2846
|
+
}
|
|
2847
|
+
/**
|
|
2848
|
+
* Helper function to create a sampling handler with proper TypeScript types.
|
|
2849
|
+
*
|
|
2850
|
+
* @param handler - Function that handles sampling requests
|
|
2851
|
+
* @returns Properly typed ADK sampling handler
|
|
2852
|
+
*
|
|
2853
|
+
* @example
|
|
2854
|
+
* ```typescript
|
|
2855
|
+
* import { createSamplingHandler, GoogleLLM, LLMRequest } from "@iqai/adk";
|
|
2856
|
+
*
|
|
2857
|
+
* const llm = new GoogleLLM("gemini-2.5-flash-preview-05-20");
|
|
2858
|
+
*
|
|
2859
|
+
* const samplingHandler = createSamplingHandler(async (request) => {
|
|
2860
|
+
* // request is properly typed with all the fields
|
|
2861
|
+
* const llmRequest = new LLMRequest({
|
|
2862
|
+
* messages: request.messages,
|
|
2863
|
+
* config: {
|
|
2864
|
+
* temperature: request.temperature || 0.7,
|
|
2865
|
+
* max_tokens: request.maxTokens,
|
|
2866
|
+
* }
|
|
2867
|
+
* });
|
|
2868
|
+
*
|
|
2869
|
+
* const responses = [];
|
|
2870
|
+
* for await (const response of llm.generateContentAsync(llmRequest)) {
|
|
2871
|
+
* responses.push(response);
|
|
2872
|
+
* }
|
|
2873
|
+
*
|
|
2874
|
+
* return {
|
|
2875
|
+
* model: llm.model,
|
|
2876
|
+
* content: responses[responses.length - 1].content,
|
|
2877
|
+
* stopReason: "endTurn"
|
|
2878
|
+
* };
|
|
2879
|
+
* });
|
|
2880
|
+
* ```
|
|
2881
|
+
*/
|
|
2882
|
+
declare function createSamplingHandler(handler: SamplingHandler): SamplingHandler;
|
|
2883
|
+
|
|
2841
2884
|
/**
|
|
2842
2885
|
* A class for managing MCP tools similar to Python's MCPToolset.
|
|
2843
2886
|
* Provides functionality to retrieve and use tools from an MCP server.
|
|
@@ -2858,6 +2901,17 @@ declare class McpToolset {
|
|
|
2858
2901
|
* Initializes the client service and establishes a connection.
|
|
2859
2902
|
*/
|
|
2860
2903
|
initialize(): Promise<McpClientService>;
|
|
2904
|
+
/**
|
|
2905
|
+
* Set a sampling handler for this MCP toolset.
|
|
2906
|
+
* This allows MCP servers to request LLM completions through your ADK agent.
|
|
2907
|
+
*
|
|
2908
|
+
* @param handler - ADK sampling handler that receives ADK-formatted messages
|
|
2909
|
+
*/
|
|
2910
|
+
setSamplingHandler(handler: SamplingHandler): void;
|
|
2911
|
+
/**
|
|
2912
|
+
* Remove the sampling handler
|
|
2913
|
+
*/
|
|
2914
|
+
removeSamplingHandler(): void;
|
|
2861
2915
|
/**
|
|
2862
2916
|
* Retrieves tools from the MCP server and converts them to BaseTool instances.
|
|
2863
2917
|
* Similar to Python's get_tools method.
|
|
@@ -2920,11 +2974,14 @@ type index$2_McpError = McpError;
|
|
|
2920
2974
|
declare const index$2_McpError: typeof McpError;
|
|
2921
2975
|
type index$2_McpErrorType = McpErrorType;
|
|
2922
2976
|
declare const index$2_McpErrorType: typeof McpErrorType;
|
|
2977
|
+
type index$2_McpSamplingHandler = McpSamplingHandler;
|
|
2978
|
+
declare const index$2_McpSamplingHandler: typeof McpSamplingHandler;
|
|
2979
|
+
type index$2_McpSamplingRequest = McpSamplingRequest;
|
|
2980
|
+
type index$2_McpSamplingResponse = McpSamplingResponse;
|
|
2923
2981
|
type index$2_McpToolset = McpToolset;
|
|
2924
2982
|
declare const index$2_McpToolset: typeof McpToolset;
|
|
2925
2983
|
type index$2_McpTransportType = McpTransportType;
|
|
2926
|
-
type index$
|
|
2927
|
-
type index$2_SamplingResponse = SamplingResponse;
|
|
2984
|
+
type index$2_SamplingHandler = SamplingHandler;
|
|
2928
2985
|
type index$2_ToolConfig = ToolConfig;
|
|
2929
2986
|
type index$2_ToolContext = ToolContext;
|
|
2930
2987
|
declare const index$2_ToolContext: typeof ToolContext;
|
|
@@ -2935,12 +2992,13 @@ declare const index$2_UserInteractionTool: typeof UserInteractionTool;
|
|
|
2935
2992
|
declare const index$2_adkToMcpToolType: typeof adkToMcpToolType;
|
|
2936
2993
|
declare const index$2_buildFunctionDeclaration: typeof buildFunctionDeclaration;
|
|
2937
2994
|
declare const index$2_createFunctionTool: typeof createFunctionTool;
|
|
2995
|
+
declare const index$2_createSamplingHandler: typeof createSamplingHandler;
|
|
2938
2996
|
declare const index$2_getMcpTools: typeof getMcpTools;
|
|
2939
2997
|
declare const index$2_jsonSchemaToDeclaration: typeof jsonSchemaToDeclaration;
|
|
2940
2998
|
declare const index$2_mcpSchemaToParameters: typeof mcpSchemaToParameters;
|
|
2941
2999
|
declare const index$2_normalizeJsonSchema: typeof normalizeJsonSchema;
|
|
2942
3000
|
declare namespace index$2 {
|
|
2943
|
-
export { index$2_BaseTool as BaseTool, type index$2_BuildFunctionDeclarationOptions as BuildFunctionDeclarationOptions, index$2_ExitLoopTool as ExitLoopTool, index$2_FileOperationsTool as FileOperationsTool, index$2_FunctionTool as FunctionTool, index$2_GetUserChoiceTool as GetUserChoiceTool, index$2_GoogleSearch as GoogleSearch, index$2_HttpRequestTool as HttpRequestTool, type index$2_IToolContext as IToolContext, index$2_LoadMemoryTool as LoadMemoryTool, type index$2_McpConfig as McpConfig, index$2_McpError as McpError, index$2_McpErrorType as McpErrorType, index$
|
|
3001
|
+
export { index$2_BaseTool as BaseTool, type index$2_BuildFunctionDeclarationOptions as BuildFunctionDeclarationOptions, index$2_ExitLoopTool as ExitLoopTool, index$2_FileOperationsTool as FileOperationsTool, index$2_FunctionTool as FunctionTool, index$2_GetUserChoiceTool as GetUserChoiceTool, index$2_GoogleSearch as GoogleSearch, index$2_HttpRequestTool as HttpRequestTool, type index$2_IToolContext as IToolContext, index$2_LoadMemoryTool as LoadMemoryTool, type index$2_McpConfig as McpConfig, index$2_McpError as McpError, index$2_McpErrorType as McpErrorType, index$2_McpSamplingHandler as McpSamplingHandler, type index$2_McpSamplingRequest as McpSamplingRequest, type index$2_McpSamplingResponse as McpSamplingResponse, index$2_McpToolset as McpToolset, type index$2_McpTransportType as McpTransportType, type index$2_SamplingHandler as SamplingHandler, type index$2_ToolConfig as ToolConfig, index$2_ToolContext as ToolContext, index$2_TransferToAgentTool as TransferToAgentTool, index$2_UserInteractionTool as UserInteractionTool, index$2_adkToMcpToolType as adkToMcpToolType, index$2_buildFunctionDeclaration as buildFunctionDeclaration, index$2_createFunctionTool as createFunctionTool, index$2_createSamplingHandler as createSamplingHandler, index$2_getMcpTools as getMcpTools, index$2_jsonSchemaToDeclaration as jsonSchemaToDeclaration, index$2_mcpSchemaToParameters as mcpSchemaToParameters, index$2_normalizeJsonSchema as normalizeJsonSchema };
|
|
2944
3002
|
}
|
|
2945
3003
|
|
|
2946
3004
|
/**
|
|
@@ -3499,4 +3557,4 @@ declare class InMemoryRunner extends Runner {
|
|
|
3499
3557
|
|
|
3500
3558
|
declare const VERSION = "0.1.0";
|
|
3501
3559
|
|
|
3502
|
-
export { Agent, type AgentConfig, index$3 as Agents, AnthropicLLM, type AnthropicLLMConfig, AnthropicLLMConnection, ApiKeyCredential, ApiKeyScheme, type AudioTranscriptionConfig, AuthConfig, AuthCredential, AuthCredentialType, AuthHandler, AuthScheme, AuthSchemeType, BaseAgent, BaseLLM, BaseLLMConnection, type BaseMemoryService, BaseTool, BasicAuthCredential, BearerTokenCredential, type BuildFunctionDeclarationOptions, ExitLoopTool, FileOperationsTool, type FunctionCall, type FunctionDeclaration, FunctionTool, GetUserChoiceTool, GoogleLLM, type GoogleLLMConfig, GoogleSearch, HttpRequestTool, HttpScheme, type IToolContext, type ImageContent, InMemoryMemoryService, InMemoryRunner, InMemorySessionService, InvocationContext, type JSONSchema, LLMRegistry, LLMRequest, type LLMRequestConfig, LLMResponse, LangGraphAgent, type LangGraphAgentConfig, type LangGraphNode, type ListSessionOptions, LoadMemoryTool, LoopAgent, type LoopAgentConfig, type McpConfig, McpError, McpErrorType, McpToolset, type McpTransportType, index$1 as Memory, type MemoryResult, type Message, type MessageContent, type MessageRole, index$4 as Models, OAuth2Credential, OAuth2Scheme, type OAuthFlow, type OAuthFlows, OpenAILLM, type OpenAILLMConfig, OpenAILLMConnection, OpenIdConnectScheme, ParallelAgent, type ParallelAgentConfig, PersistentMemoryService, PgLiteSessionService, PostgresSessionService, RunConfig, Runner, type
|
|
3560
|
+
export { Agent, type AgentConfig, index$3 as Agents, AnthropicLLM, type AnthropicLLMConfig, AnthropicLLMConnection, ApiKeyCredential, ApiKeyScheme, type AudioTranscriptionConfig, AuthConfig, AuthCredential, AuthCredentialType, AuthHandler, AuthScheme, AuthSchemeType, BaseAgent, BaseLLM, BaseLLMConnection, type BaseMemoryService, BaseTool, BasicAuthCredential, BearerTokenCredential, type BuildFunctionDeclarationOptions, ExitLoopTool, FileOperationsTool, type FunctionCall, type FunctionDeclaration, FunctionTool, GetUserChoiceTool, GoogleLLM, type GoogleLLMConfig, GoogleSearch, HttpRequestTool, HttpScheme, type IToolContext, type ImageContent, InMemoryMemoryService, InMemoryRunner, InMemorySessionService, InvocationContext, type JSONSchema, LLMRegistry, LLMRequest, type LLMRequestConfig, LLMResponse, LangGraphAgent, type LangGraphAgentConfig, type LangGraphNode, type ListSessionOptions, LoadMemoryTool, LoopAgent, type LoopAgentConfig, type McpConfig, McpError, McpErrorType, McpSamplingHandler, type McpSamplingRequest, type McpSamplingResponse, McpToolset, type McpTransportType, index$1 as Memory, type MemoryResult, type Message, type MessageContent, type MessageRole, index$4 as Models, OAuth2Credential, OAuth2Scheme, type OAuthFlow, type OAuthFlows, OpenAILLM, type OpenAILLMConfig, OpenAILLMConnection, OpenIdConnectScheme, ParallelAgent, type ParallelAgentConfig, PersistentMemoryService, PgLiteSessionService, PostgresSessionService, RunConfig, Runner, type SamplingHandler, type SearchMemoryOptions, type SearchMemoryResponse, SequentialAgent, type SequentialAgentConfig, type Session, type SessionService, SessionState, index as Sessions, type SpeechConfig, SqliteSessionService, StreamingMode, type TextContent, type ToolCall, type ToolConfig, ToolContext, index$2 as Tools, TransferToAgentTool, UserInteractionTool, VERSION, adkToMcpToolType, buildFunctionDeclaration, cloneSession, createFunctionTool, createSamplingHandler, generateSessionId, getMcpTools, jsonSchemaToDeclaration, mcpSchemaToParameters, normalizeJsonSchema, registerProviders, validateSession };
|