Skip to content

Commit 0549fa2

Browse files
committed
fix: tool path
1 parent 9df8fec commit 0549fa2

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed

src/tools/definitions/get-device-documentation.tool.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ function readDocumentation(topic: string): string {
3434

3535
try {
3636
const fileName = fileMap[topic];
37-
const filePath = path.join(__dirname, '../../../docs/ai-resources', fileName);
37+
// Use process.cwd() instead of __dirname for consistent path resolution
38+
const filePath = path.join(process.cwd(), 'docs', 'ai-resources', fileName);
3839
return fs.readFileSync(filePath, 'utf-8');
3940
} catch (error) {
4041
return `Error loading documentation: ${error.message}`;
@@ -54,7 +55,7 @@ function readDocumentation(topic: string): string {
5455
export const GET_DEVICE_DOCUMENTATION_TOOL = {
5556
name: 'get_device_documentation',
5657
description:
57-
'Get comprehensive documentation about IoT device control. Call this when you need details about device concepts, available commands, control workflows, or state structure. Returns full markdown documentation.',
58+
'Get device control documentation. Available topics: "overview" (core concepts/fields), "device_attributes" (commands/device types), "control_guide" (how to control devices), "state_guide" (reading device state). Returns markdown documentation.',
5859
inputSchema: {
5960
type: 'object' as const,
6061
properties: {
@@ -70,7 +71,7 @@ export const GET_DEVICE_DOCUMENTATION_TOOL = {
7071
metadata: {
7172
name: 'get_device_documentation',
7273
description:
73-
'Get comprehensive documentation about IoT device control. Call this when you need details about device concepts, available commands, control workflows, or state structure. Returns full markdown documentation.',
74+
'Get device control documentation. Available topics: "overview" (core concepts/fields), "device_attributes" (commands/device types), "control_guide" (how to control devices), "state_guide" (reading device state). Returns markdown documentation.',
7475
readOnlyHint: true,
7576
securitySchemes: {
7677
oauth2: {

src/tools/services/tool-executor.service.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ export class ToolExecutorService {
130130
return 'controlDeviceSimple tool requires an "action" parameter of type string.';
131131
}
132132
break;
133+
case 'get_device_documentation':
134+
if (!params.topic || typeof params.topic !== 'string') {
135+
return 'get_device_documentation tool requires a "topic" parameter of type string.';
136+
}
137+
const validTopics = ['overview', 'device_attributes', 'control_guide', 'state_guide'];
138+
if (!validTopics.includes(params.topic as string)) {
139+
return `get_device_documentation tool requires topic to be one of: ${validTopics.join(', ')}`;
140+
}
141+
break;
133142
default:
134143
return `Unknown tool: ${toolName}`;
135144
}
@@ -222,6 +231,11 @@ export class ToolExecutorService {
222231
return this.executeControlDeviceSimple(params as ControlDeviceSimpleParams, context);
223232
}
224233

234+
if (toolName === 'get_device_documentation') {
235+
return this.executeGetDeviceDocumentation(params as { topic: string });
236+
}
237+
238+
225239
throw new BadRequestException(`Unknown tool: ${toolName}`);
226240
}
227241

@@ -1286,4 +1300,42 @@ export class ToolExecutorService {
12861300
};
12871301
}
12881302
}
1303+
1304+
/**
1305+
* Execute get_device_documentation tool
1306+
* Returns documentation markdown content
1307+
*
1308+
* @param params - Tool parameters including topic
1309+
* @returns MCP-formatted documentation content
1310+
*/
1311+
private executeGetDeviceDocumentation(
1312+
params: { topic: string },
1313+
): CallToolResult {
1314+
const GET_DEVICE_DOCUMENTATION_TOOL = require('../definitions/get-device-documentation.tool').GET_DEVICE_DOCUMENTATION_TOOL;
1315+
1316+
try {
1317+
const content = GET_DEVICE_DOCUMENTATION_TOOL.execute(params.topic);
1318+
return {
1319+
content: [
1320+
{
1321+
type: 'text' as const,
1322+
text: content,
1323+
},
1324+
],
1325+
};
1326+
} catch (error) {
1327+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
1328+
return {
1329+
content: [
1330+
{
1331+
type: 'text' as const,
1332+
text: JSON.stringify({
1333+
isError: true,
1334+
error: errorMessage,
1335+
}),
1336+
},
1337+
],
1338+
};
1339+
}
1340+
}
12891341
}

0 commit comments

Comments
 (0)