mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-14 12:44:36 +00:00
Bump to 1.0.31: default ToothFairy MCP tools to stored credentials
When api_key and workspace_id are not provided, ToothFairy MCP tools now default to credentials stored in ~/.tfcode/credentials.json (from tfcode validate).
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/package.json",
|
||||
"version": "1.0.30",
|
||||
"version": "1.0.31",
|
||||
"name": "@toothfairyai/tfcode",
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -24,6 +24,8 @@ import { BusEvent } from "../bus/bus-event"
|
||||
import { Bus } from "@/bus"
|
||||
import { TuiEvent } from "@/cli/cmd/tui/event"
|
||||
import open from "open"
|
||||
import path from "path"
|
||||
import { Global } from "../global"
|
||||
|
||||
export namespace MCP {
|
||||
const log = Log.create({ service: "mcp" })
|
||||
@@ -117,6 +119,16 @@ export namespace MCP {
|
||||
})
|
||||
}
|
||||
|
||||
async function loadTFCredentials(): Promise<{ api_key?: string; workspace_id?: string; region?: string }> {
|
||||
try {
|
||||
const credPath = path.join(Global.Path.data, ".tfcode", "credentials.json")
|
||||
const content = await Bun.file(credPath).text()
|
||||
return JSON.parse(content)
|
||||
} catch {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
// Convert MCP tool definition to AI SDK Tool type
|
||||
async function convertMcpTool(mcpTool: MCPToolDef, client: MCPClient, timeout?: number): Promise<Tool> {
|
||||
const inputSchema = mcpTool.inputSchema
|
||||
@@ -129,14 +141,29 @@ export namespace MCP {
|
||||
additionalProperties: false,
|
||||
}
|
||||
|
||||
const isTFCredTool = (name: string) =>
|
||||
name.startsWith("toothfairy_") && (schema.properties?.api_key || schema.properties?.workspace_id)
|
||||
|
||||
return dynamicTool({
|
||||
description: mcpTool.description ?? "",
|
||||
inputSchema: jsonSchema(schema),
|
||||
execute: async (args: unknown) => {
|
||||
let finalArgs = (args || {}) as Record<string, unknown>
|
||||
|
||||
if (isTFCredTool(mcpTool.name)) {
|
||||
const creds = await loadTFCredentials()
|
||||
finalArgs = {
|
||||
...finalArgs,
|
||||
api_key: finalArgs.api_key || creds.api_key,
|
||||
workspace_id: finalArgs.workspace_id || creds.workspace_id,
|
||||
region: finalArgs.region || creds.region || "au",
|
||||
}
|
||||
}
|
||||
|
||||
return client.callTool(
|
||||
{
|
||||
name: mcpTool.name,
|
||||
arguments: (args || {}) as Record<string, unknown>,
|
||||
arguments: finalArgs,
|
||||
},
|
||||
CallToolResultSchema,
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user