@oh-my-tool/cli 0.2.0 → 0.3.1

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.
Files changed (49) hide show
  1. package/README.md +7 -2
  2. package/assets/skills/oh-my-tool/SKILL.md +11 -3
  3. package/bin/ohmytool.cjs +0 -0
  4. package/package.json +20 -11
  5. package/src/cli/commands/connections.ts +98 -0
  6. package/src/cli/commands/describe.ts +23 -22
  7. package/src/cli/commands/extension.ts +24 -24
  8. package/src/cli/commands/index.ts +8 -6
  9. package/src/cli/commands/integrate.ts +64 -64
  10. package/src/cli/commands/mcp.ts +86 -0
  11. package/src/cli/commands/run.ts +14 -8
  12. package/src/cli/commands/search.ts +14 -13
  13. package/src/cli/commands/secret.ts +68 -68
  14. package/src/cli/context.ts +37 -4
  15. package/src/cli/index.ts +338 -273
  16. package/src/cli/output.ts +165 -0
  17. package/src/cli/parseArgs.ts +64 -44
  18. package/src/config/config.ts +207 -63
  19. package/src/core/executor.ts +89 -89
  20. package/src/core/registry.ts +31 -31
  21. package/src/core/result.ts +14 -14
  22. package/src/extension/discovery.ts +61 -61
  23. package/src/extension/install.ts +23 -23
  24. package/src/extension/loader.ts +32 -32
  25. package/src/extension/manifest.ts +114 -114
  26. package/src/integration/adapters.ts +98 -98
  27. package/src/integration/index.ts +4 -4
  28. package/src/integration/manager.ts +375 -375
  29. package/src/integration/skill.ts +84 -84
  30. package/src/integration/types.ts +55 -55
  31. package/src/policy/policy.ts +136 -136
  32. package/src/runtime/errors.ts +7 -2
  33. package/src/runtime/executor.ts +6 -1
  34. package/src/runtime/provider.ts +2 -1
  35. package/src/runtime/providers/mcp/normalize.ts +36 -0
  36. package/src/runtime/providers/mcp/oauth-callback.ts +91 -0
  37. package/src/runtime/providers/mcp/oauth-provider.ts +348 -0
  38. package/src/runtime/providers/mcp/oauth-store.ts +106 -0
  39. package/src/runtime/providers/mcp/provider.ts +99 -0
  40. package/src/runtime/providers/mcp/safe-errors.ts +63 -0
  41. package/src/runtime/providers/mcp/session.ts +117 -0
  42. package/src/runtime/providers/mcp/transport.ts +140 -0
  43. package/src/runtime/providers/native/provider.ts +1 -1
  44. package/src/runtime/result.ts +1 -1
  45. package/src/runtime/runtime.ts +38 -12
  46. package/src/runtime/schema.ts +14 -4
  47. package/src/search/search.ts +78 -78
  48. package/src/secrets/secrets.ts +45 -45
  49. package/src/version.ts +1 -1
package/README.md CHANGED
@@ -9,5 +9,10 @@ ohmytool --help
9
9
  ```
10
10
 
11
11
  Requires Bun 1.4 or newer. Use `ohmytool search`, `ohmytool describe`, then
12
- `ohmytool run`; see the main [Oh My Tool repository](https://github.com/oh-my-tool/oh-my-tool)
13
- for configuration and extension installation guidance.
12
+ `ohmytool run` for both native and MCP-backed tools. Configure MCP servers in
13
+ `config.toml`; use `ohmytool mcp list` to inspect configured servers and
14
+ `ohmytool mcp auth <server>` / `ohmytool mcp logout <server>` for interactive
15
+ OAuth credentials. See the main
16
+ [Oh My Tool repository](https://github.com/oh-my-tool/oh-my-tool) and
17
+ [`docs/configuration.md`](../../docs/configuration.md) for configuration and
18
+ secret-management guidance.
@@ -5,7 +5,8 @@ description: Discover and invoke local, development, and enterprise tools throug
5
5
 
6
6
  # Oh My Tool — The Agent Tool Runtime
7
7
 
8
- Use the canonical `ohmytool` CLI to discover and execute tools exposed by installed native extensions.
8
+ Use the canonical `ohmytool` CLI to discover and execute tools exposed by
9
+ installed native extensions and enabled MCP servers.
9
10
 
10
11
  ## When to use
11
12
 
@@ -29,7 +30,8 @@ When you do not know the exact tool ID:
29
30
  ohmytool search "<what you need to do>"
30
31
  ```
31
32
 
32
- Search returns lightweight summary metadata and does not load handlers or access secrets.
33
+ Search returns lightweight summary metadata. Native discovery reads manifests;
34
+ MCP discovery connects to enabled servers and obtains `tools/list`.
33
35
 
34
36
  ### 2. Describe
35
37
 
@@ -43,7 +45,8 @@ Use the returned schema, constraints, risk level, and configuration requirements
43
45
 
44
46
  ### 3. Run
45
47
 
46
- Execute the selected tool through the runtime:
48
+ Execute the selected tool through the runtime. Use the exact namespaced ID
49
+ returned by search/describe for MCP tools:
47
50
 
48
51
  ```bash
49
52
  ohmytool run <tool-name> key=value
@@ -62,6 +65,11 @@ echo '{"connection":"iot-test","sql":"SELECT 1"}' | ohmytool run mysql.query --s
62
65
  - Do not guess tool arguments; use `ohmytool describe`.
63
66
  - Do not guess connection names, endpoints, credentials, tokens, or authentication details.
64
67
  - Never request or expose secrets managed by Oh My Tool.
68
+ - Provider origin does not change the `search → describe → run` sequence.
69
+ - Never place bearer tokens, OAuth tokens, authorization codes, client secrets,
70
+ or secret environment values in tool arguments.
71
+ - If a command returns `MCP_AUTH_REQUIRED`, ask the user to run or approve
72
+ `ohmytool mcp auth <server-id>`; never collect credentials in chat.
65
73
  - Respect tool risk levels, policy restrictions, and environment restrictions.
66
74
  - Prefer the smallest and safest tool that can complete the task.
67
75
  - Treat runtime results as structured tool output and use them to continue the task.
package/bin/ohmytool.cjs CHANGED
File without changes
package/package.json CHANGED
@@ -1,9 +1,16 @@
1
- {
2
- "name": "@oh-my-tool/cli",
3
- "version": "0.2.0",
1
+ {
2
+ "name": "@oh-my-tool/cli",
3
+ "version": "0.3.1",
4
4
  "type": "module",
5
5
  "description": "Oh My Tool CLI - local and enterprise tools for agents",
6
- "keywords": ["ai", "agent", "cli", "tools", "extensions", "bun"],
6
+ "keywords": [
7
+ "ai",
8
+ "agent",
9
+ "cli",
10
+ "tools",
11
+ "extensions",
12
+ "bun"
13
+ ],
7
14
  "homepage": "https://github.com/oh-my-tool/oh-my-tool#readme",
8
15
  "repository": {
9
16
  "type": "git",
@@ -13,15 +20,17 @@
13
20
  "bugs": "https://github.com/oh-my-tool/oh-my-tool/issues",
14
21
  "bin": {
15
22
  "ohmytool": "bin/ohmytool.cjs"
16
- },
17
- "files": [
18
- "assets",
19
- "bin",
20
- "src"
21
- ],
23
+ },
24
+ "files": [
25
+ "assets",
26
+ "bin",
27
+ "src"
28
+ ],
22
29
  "dependencies": {
23
30
  "@clack/prompts": "^1.7.0",
24
- "@oh-my-tool/sdk": "0.2.0"
31
+ "@modelcontextprotocol/client": "2.0.0",
32
+ "@oh-my-tool/sdk": "0.3.1",
33
+ "open": "11.0.0"
25
34
  },
26
35
  "engines": {
27
36
  "node": ">=20",
@@ -0,0 +1,98 @@
1
+ import { loadConfig } from "../../config/config";
2
+ import { createPaths } from "../../paths";
3
+ import { prepareHome } from "../../migration";
4
+ import { withRuntime } from "../context";
5
+
6
+ export interface ConnectionSummary {
7
+ extension: string;
8
+ name: string;
9
+ environment: string;
10
+ host: string;
11
+ port: number;
12
+ database: string;
13
+ username: string;
14
+ tls: boolean;
15
+ secretConfigured: boolean;
16
+ }
17
+
18
+ export interface ConnectionListResult {
19
+ connections: ConnectionSummary[];
20
+ count: number;
21
+ }
22
+
23
+ export interface ConnectionCheck {
24
+ extension: string;
25
+ name: string;
26
+ status: "ok" | "error" | "unsupported";
27
+ code?: string;
28
+ durationMs?: number;
29
+ }
30
+
31
+ export interface ConnectionCheckResult {
32
+ checks: ConnectionCheck[];
33
+ count: number;
34
+ }
35
+
36
+ export interface ConfigCheckResult {
37
+ valid: true;
38
+ connectionCount: number;
39
+ extensionCount: number;
40
+ }
41
+
42
+ async function configuredConnections(): Promise<ConnectionListResult> {
43
+ const paths = createPaths();
44
+ await prepareHome(paths);
45
+ const config = loadConfig(paths.home);
46
+ const connections = Object.entries(config.extensions)
47
+ .sort(([left], [right]) => left.localeCompare(right))
48
+ .flatMap(([extension, value]) => Object.entries(value.connections)
49
+ .sort(([left], [right]) => left.localeCompare(right))
50
+ .map(([name, connection]) => ({
51
+ extension,
52
+ name,
53
+ environment: connection.environment,
54
+ host: connection.host,
55
+ port: connection.port,
56
+ database: connection.database,
57
+ username: connection.username,
58
+ tls: connection.tls,
59
+ secretConfigured: connection.secret.length > 0,
60
+ })));
61
+ return { connections, count: connections.length };
62
+ }
63
+
64
+ export async function runConnectionList(): Promise<ConnectionListResult> {
65
+ return configuredConnections();
66
+ }
67
+
68
+ export async function runConfigCheck(): Promise<ConfigCheckResult> {
69
+ const paths = createPaths();
70
+ await prepareHome(paths);
71
+ const config = loadConfig(paths.home);
72
+ return {
73
+ valid: true,
74
+ connectionCount: Object.values(config.extensions).reduce((count, extension) => count + Object.keys(extension.connections).length, 0),
75
+ extensionCount: Object.keys(config.extensions).length,
76
+ };
77
+ }
78
+
79
+ export async function runConnectionCheck(): Promise<ConnectionCheckResult> {
80
+ const list = await configuredConnections();
81
+ return withRuntime(async (runtime) => {
82
+ const checks: ConnectionCheck[] = [];
83
+ for (const connection of list.connections) {
84
+ if (connection.extension !== "redis" && connection.extension !== "mysql") {
85
+ checks.push({ extension: connection.extension, name: connection.name, status: "unsupported", code: "CHECK_UNSUPPORTED" });
86
+ continue;
87
+ }
88
+ const started = Date.now();
89
+ const result = await runtime.run(`${connection.extension}.ping`, { connection: connection.name });
90
+ checks.push(result.ok
91
+ ? { extension: connection.extension, name: connection.name, status: "ok", durationMs: Date.now() - started }
92
+ : result.error?.code === "TOOL_NOT_FOUND"
93
+ ? { extension: connection.extension, name: connection.name, status: "unsupported", code: "CHECK_UNSUPPORTED", durationMs: Date.now() - started }
94
+ : { extension: connection.extension, name: connection.name, status: "error", code: result.error?.code ?? "CHECK_FAILED", durationMs: Date.now() - started });
95
+ }
96
+ return { checks, count: checks.length };
97
+ }, { includeMcp: false });
98
+ }
@@ -1,24 +1,25 @@
1
- import { createRuntime } from "../context";
2
-
3
- export interface DescribedTool {
4
- name: string;
5
- description: string;
6
- risk: string;
7
- inputSchema: Record<string, unknown> | undefined;
8
- extension: string;
9
- extensionVersion: string;
10
- }
11
-
1
+ import { withRuntime } from "../context";
2
+
3
+ export interface DescribedTool {
4
+ name: string;
5
+ description: string;
6
+ risk: string;
7
+ inputSchema: Record<string, unknown> | undefined;
8
+ extension: string;
9
+ extensionVersion: string;
10
+ }
11
+
12
12
  export async function runDescribe(toolName: string): Promise<DescribedTool> {
13
- const runtime = await createRuntime();
14
- const descriptor = await runtime.describe(toolName);
15
- return {
16
- name: descriptor.id,
17
- description: descriptor.description,
18
- risk: descriptor.risk,
19
- inputSchema: descriptor.inputSchema,
20
- extension: descriptor.source.id,
21
- extensionVersion: "unknown",
22
- };
13
+ return withRuntime(async (runtime) => {
14
+ const descriptor = await runtime.describe(toolName);
15
+ return {
16
+ name: descriptor.id,
17
+ description: descriptor.description,
18
+ risk: descriptor.risk,
19
+ inputSchema: descriptor.inputSchema,
20
+ extension: descriptor.source.id,
21
+ extensionVersion: descriptor.source.version ?? "unknown",
22
+ };
23
+ });
23
24
  }
24
-
25
+
@@ -1,24 +1,24 @@
1
- import { discoverExtensions } from "../../extension/discovery";
2
- import { installLocalExtension, type InstalledRef } from "../../extension/install";
3
- import { homeDir } from "../context";
4
-
5
- export interface InstalledInfo {
6
- id: string;
7
- version: string;
8
- entry: string;
9
- toolCount: number;
10
- }
11
-
12
- export async function runExtensionList(): Promise<InstalledInfo[]> {
13
- return discoverExtensions(homeDir()).map((e) => ({
14
- id: e.id,
15
- version: e.version,
16
- entry: e.entry,
17
- toolCount: e.manifest.tools.length,
18
- }));
19
- }
20
-
21
- export async function runExtensionInstall(spec: string): Promise<InstalledRef> {
22
- return installLocalExtension(homeDir(), spec);
23
- }
24
-
1
+ import { discoverExtensions } from "../../extension/discovery";
2
+ import { installLocalExtension, type InstalledRef } from "../../extension/install";
3
+ import { homeDir } from "../context";
4
+
5
+ export interface InstalledInfo {
6
+ id: string;
7
+ version: string;
8
+ entry: string;
9
+ toolCount: number;
10
+ }
11
+
12
+ export async function runExtensionList(): Promise<InstalledInfo[]> {
13
+ return discoverExtensions(homeDir()).map((e) => ({
14
+ id: e.id,
15
+ version: e.version,
16
+ entry: e.entry,
17
+ toolCount: e.manifest.tools.length,
18
+ }));
19
+ }
20
+
21
+ export async function runExtensionInstall(spec: string): Promise<InstalledRef> {
22
+ return installLocalExtension(homeDir(), spec);
23
+ }
24
+
@@ -1,7 +1,9 @@
1
- export * from "./search";
2
- export * from "./describe";
1
+ export * from "./search";
2
+ export * from "./describe";
3
3
  export * from "./run";
4
- export * from "./extension";
5
- export * from "./secret";
6
- export * from "./integrate";
7
-
4
+ export * from "./extension";
5
+ export * from "./secret";
6
+ export * from "./integrate";
7
+ export * from "./mcp";
8
+ export * from "./connections";
9
+
@@ -1,64 +1,64 @@
1
- import type { AgentDetection, AgentId, IntegrationResult } from "../../integration";
2
- import { AGENT_IDS, createIntegrationManager } from "../../integration";
3
- import { homeDir } from "../context";
4
- import { VERSION } from "../../version";
5
-
6
- export type IntegrateAction = "install" | "status" | "repair" | "uninstall";
7
-
8
- export interface IntegrateInput {
9
- action: IntegrateAction;
10
- agents?: AgentId[];
11
- force?: boolean;
12
- dryRun?: boolean;
13
- }
14
-
15
- export interface IntegrateOutput {
16
- action: IntegrateAction;
17
- dryRun: boolean;
18
- detected: AgentDetection[];
19
- selected: AgentId[];
20
- results: IntegrationResult[];
21
- }
22
-
23
- type IntegrationManager = ReturnType<typeof createIntegrationManager>;
24
-
25
- export function defaultIntegrationManager(): IntegrationManager {
26
- return createIntegrationManager({ omtHome: homeDir(), skillVersion: VERSION });
27
- }
28
-
29
- export async function runIntegrate(
30
- input: IntegrateInput,
31
- manager: IntegrationManager = defaultIntegrationManager(),
32
- ): Promise<IntegrateOutput> {
33
- const detected = await manager.detect();
34
- const known = new Set<AgentId>(AGENT_IDS);
35
- for (const id of input.agents ?? []) {
36
- if (!known.has(id)) throw new Error(`Unknown agent: ${id}`);
37
- }
38
- const selected = input.agents?.length ? input.agents : detected.map((agent) => agent.id);
39
- const detectedIds = new Set(detected.map((agent) => agent.id));
40
- for (const id of selected) {
41
- if (!detectedIds.has(id)) throw new Error(`Agent is not detected: ${id}`);
42
- }
43
-
44
- if (input.dryRun) {
45
- return { action: input.action, dryRun: true, detected, selected, results: [] };
46
- }
47
-
48
- let results: IntegrationResult[];
49
- switch (input.action) {
50
- case "install":
51
- results = await manager.install(selected, { force: input.force });
52
- break;
53
- case "status":
54
- results = (await manager.status()).filter((item) => selected.includes(item.agent));
55
- break;
56
- case "repair":
57
- results = await manager.repair(selected);
58
- break;
59
- case "uninstall":
60
- results = await manager.uninstall(selected);
61
- break;
62
- }
63
- return { action: input.action, dryRun: false, detected, selected, results };
64
- }
1
+ import type { AgentDetection, AgentId, IntegrationResult } from "../../integration";
2
+ import { AGENT_IDS, createIntegrationManager } from "../../integration";
3
+ import { homeDir } from "../context";
4
+ import { VERSION } from "../../version";
5
+
6
+ export type IntegrateAction = "install" | "status" | "repair" | "uninstall";
7
+
8
+ export interface IntegrateInput {
9
+ action: IntegrateAction;
10
+ agents?: AgentId[];
11
+ force?: boolean;
12
+ dryRun?: boolean;
13
+ }
14
+
15
+ export interface IntegrateOutput {
16
+ action: IntegrateAction;
17
+ dryRun: boolean;
18
+ detected: AgentDetection[];
19
+ selected: AgentId[];
20
+ results: IntegrationResult[];
21
+ }
22
+
23
+ type IntegrationManager = ReturnType<typeof createIntegrationManager>;
24
+
25
+ export function defaultIntegrationManager(): IntegrationManager {
26
+ return createIntegrationManager({ omtHome: homeDir(), skillVersion: VERSION });
27
+ }
28
+
29
+ export async function runIntegrate(
30
+ input: IntegrateInput,
31
+ manager: IntegrationManager = defaultIntegrationManager(),
32
+ ): Promise<IntegrateOutput> {
33
+ const detected = await manager.detect();
34
+ const known = new Set<AgentId>(AGENT_IDS);
35
+ for (const id of input.agents ?? []) {
36
+ if (!known.has(id)) throw new Error(`Unknown agent: ${id}`);
37
+ }
38
+ const selected = input.agents?.length ? input.agents : detected.map((agent) => agent.id);
39
+ const detectedIds = new Set(detected.map((agent) => agent.id));
40
+ for (const id of selected) {
41
+ if (!detectedIds.has(id)) throw new Error(`Agent is not detected: ${id}`);
42
+ }
43
+
44
+ if (input.dryRun) {
45
+ return { action: input.action, dryRun: true, detected, selected, results: [] };
46
+ }
47
+
48
+ let results: IntegrationResult[];
49
+ switch (input.action) {
50
+ case "install":
51
+ results = await manager.install(selected, { force: input.force });
52
+ break;
53
+ case "status":
54
+ results = (await manager.status()).filter((item) => selected.includes(item.agent));
55
+ break;
56
+ case "repair":
57
+ results = await manager.repair(selected);
58
+ break;
59
+ case "uninstall":
60
+ results = await manager.uninstall(selected);
61
+ break;
62
+ }
63
+ return { action: input.action, dryRun: false, detected, selected, results };
64
+ }
@@ -0,0 +1,86 @@
1
+ import type { SecretStore } from "@oh-my-tool/sdk";
2
+ import type { McpHttpServerConfig, McpServerConfig } from "../../config/config";
3
+ import { loadConfig } from "../../config/config";
4
+ import { prepareHome } from "../../migration";
5
+ import { createPaths } from "../../paths";
6
+ import { RuntimeError } from "../../runtime/errors";
7
+ import {
8
+ authorizeMcpServer,
9
+ logoutMcpServer,
10
+ } from "../../runtime/providers/mcp/oauth-provider";
11
+ import { SecretsManager } from "../../secrets/secrets";
12
+
13
+ export interface McpCommandDependencies {
14
+ readonly secrets?: SecretStore;
15
+ readonly authorize?: typeof authorizeMcpServer;
16
+ readonly logout?: typeof logoutMcpServer;
17
+ }
18
+
19
+ export interface McpServerSummary {
20
+ readonly id: string;
21
+ readonly enabled: boolean;
22
+ readonly transport: McpServerConfig["transport"];
23
+ readonly namespace: string;
24
+ readonly auth: "none" | "bearer" | "oauth" | "disabled";
25
+ }
26
+
27
+ export interface McpListResult {
28
+ readonly servers: McpServerSummary[];
29
+ }
30
+
31
+ /** List configured MCP servers without connecting to them or exposing secrets. */
32
+ export async function runMcpList(): Promise<McpListResult> {
33
+ const paths = createPaths();
34
+ await prepareHome(paths);
35
+ const config = loadConfig(paths.home);
36
+ const servers = Object.entries(config.mcp.servers)
37
+ .sort(([left], [right]) => left.localeCompare(right))
38
+ .map(([id, server]) => ({
39
+ id,
40
+ enabled: server.enabled,
41
+ transport: server.transport,
42
+ namespace: server.namespace,
43
+ auth: server.transport === "disabled"
44
+ ? "disabled" as const
45
+ : server.transport === "stdio"
46
+ ? "none" as const
47
+ : server.auth.type,
48
+ }));
49
+ return { servers };
50
+ }
51
+
52
+ function oauthTarget(serverId: string, config: McpServerConfig | undefined): McpHttpServerConfig {
53
+ if (config === undefined || !config.enabled || config.transport !== "streamable-http" || config.auth.type !== "oauth") {
54
+ throw new RuntimeError("MCP_OAUTH_NOT_CONFIGURED", `MCP server '${serverId}' is not an enabled OAuth Streamable HTTP server`);
55
+ }
56
+ return config;
57
+ }
58
+
59
+ async function commandContext(serverId: string, secrets?: SecretStore): Promise<{
60
+ config: McpHttpServerConfig;
61
+ secrets: SecretStore;
62
+ }> {
63
+ const paths = createPaths();
64
+ await prepareHome(paths);
65
+ const config = loadConfig(paths.home);
66
+ return {
67
+ config: oauthTarget(serverId, config.mcp.servers[serverId]),
68
+ secrets: secrets ?? new SecretsManager(),
69
+ };
70
+ }
71
+
72
+ export async function runMcpAuth(
73
+ serverId: string,
74
+ dependencies: McpCommandDependencies = {},
75
+ ): Promise<{ serverId: string; authorized: true }> {
76
+ const context = await commandContext(serverId, dependencies.secrets);
77
+ return (dependencies.authorize ?? authorizeMcpServer)(serverId, context.config, context.secrets);
78
+ }
79
+
80
+ export async function runMcpLogout(
81
+ serverId: string,
82
+ dependencies: McpCommandDependencies = {},
83
+ ): Promise<{ serverId: string; loggedOut: true }> {
84
+ const context = await commandContext(serverId, dependencies.secrets);
85
+ return (dependencies.logout ?? logoutMcpServer)(serverId, context.config, context.secrets);
86
+ }
@@ -1,5 +1,5 @@
1
1
  import { coerceInput } from "../parseArgs";
2
- import { createRuntime } from "../context";
2
+ import { withRuntime } from "../context";
3
3
  import type { OmtResult } from "../../core/result";
4
4
 
5
5
  export async function runTool(
@@ -13,12 +13,13 @@ export async function runTool(
13
13
  } else {
14
14
  input = coerceInput(keyValues);
15
15
  }
16
- const runtime = await createRuntime();
17
- const result = await runtime.run(toolName, input);
18
- if (result.ok) {
19
- return { ok: true, tool: toolName, data: result.output, meta: result.meta ?? {} };
20
- }
21
- return { ok: false, tool: toolName, error: result.error ?? { code: "EXECUTION_FAILED", message: "execution failed" } };
16
+ return withRuntime(async (runtime) => {
17
+ const result = await runtime.run(toolName, input);
18
+ if (result.ok) {
19
+ return { ok: true, tool: toolName, data: result.output, meta: result.meta ?? {} };
20
+ }
21
+ return { ok: false, tool: toolName, error: result.error ?? { code: "EXECUTION_FAILED", message: "execution failed" } };
22
+ }, { targetTool: toolName });
22
23
  }
23
24
 
24
25
  function readStdinJson(): Promise<Record<string, unknown>> {
@@ -29,7 +30,12 @@ function readStdinJson(): Promise<Record<string, unknown>> {
29
30
  stdin.on("data", (chunk: string) => (data += chunk));
30
31
  stdin.on("end", () => {
31
32
  try {
32
- resolve(JSON.parse(data));
33
+ const parsed: unknown = JSON.parse(data);
34
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
35
+ reject(new Error("stdin JSON must be an object"));
36
+ return;
37
+ }
38
+ resolve(parsed as Record<string, unknown>);
33
39
  } catch (e) {
34
40
  reject(e);
35
41
  }
@@ -1,16 +1,17 @@
1
- import { createRuntime } from "../context";
1
+ import { withRuntime } from "../context";
2
2
 
3
3
  export async function runSearch(query: string): Promise<{ tools: Array<Record<string, unknown>> }> {
4
- const runtime = await createRuntime();
5
- const descriptors = await runtime.search(query);
6
- return {
7
- tools: descriptors.map((descriptor) => ({
8
- name: descriptor.id,
9
- description: descriptor.description,
10
- extension: descriptor.source.id,
11
- risk: descriptor.risk,
12
- provider: descriptor.provider,
13
- })),
14
- };
4
+ return withRuntime(async (runtime) => {
5
+ const descriptors = await runtime.search(query);
6
+ return {
7
+ tools: descriptors.map((descriptor) => ({
8
+ name: descriptor.id,
9
+ description: descriptor.description,
10
+ extension: descriptor.source.id,
11
+ risk: descriptor.risk,
12
+ provider: descriptor.provider,
13
+ })),
14
+ };
15
+ });
15
16
  }
16
-
17
+