Skip to content

Commit abe6a25

Browse files
Re-org logic
1 parent 09fd77e commit abe6a25

3 files changed

Lines changed: 37 additions & 34 deletions

File tree

libs/mcp/language-server-tools/src/lib/tasks/register-mcp-task-tools.ts

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,9 @@ import {
66
RegisterMCPTool_ListENVITools,
77
RegisterMCPTool_RunENVITool,
88
} from '@idl/mcp/server-tools';
9-
import { FilterMCPENVITasks, MCPTaskRegistry } from '@idl/mcp/tasks';
9+
import { MCPTaskRegistry } from '@idl/mcp/tasks';
1010
import { IDLIndex } from '@idl/parsing/index';
11-
import {
12-
GLOBAL_TOKEN_TYPES,
13-
GlobalFunctionToken,
14-
GlobalStructureToken,
15-
IGlobalIndexedToken,
16-
} from '@idl/types/idl-data-types';
11+
import { GLOBAL_TOKEN_TYPES } from '@idl/types/idl-data-types';
1712

1813
/**
1914
* Registers MCP Task tools from parsed code on IDL's search path
@@ -46,30 +41,11 @@ export async function RegisterMCPTaskTools(server: MCPServer, index: IDLIndex) {
4641
RegisterMCPTool_RunENVITool(server, registry);
4742
RegisterMCPTool_CreateENVIModelerWorkflow(server, registry);
4843

49-
/** Get all functions that we know about */
50-
const functions =
51-
index.globalIndex.globalTokensByTypeByName[GLOBAL_TOKEN_TYPES.FUNCTION];
52-
53-
/** Get all structures that we know about */
54-
const structures =
55-
index.globalIndex.globalTokensByTypeByName[GLOBAL_TOKEN_TYPES.STRUCTURE];
56-
57-
/** Find names of ENVI Tasks and exclude those we dont need to expose */
58-
const keys = FilterMCPENVITasks(functions, Object.keys(structures)).sort();
59-
60-
server.logManager.log({
61-
log: IDL_MCP_LOG,
62-
type: 'info',
63-
content: `Attempting to register ${keys.length} ENVI Tools`,
64-
});
65-
66-
// add all ENVI Tasks
67-
for (let i = 0; i < keys.length; i++) {
68-
registry.registerTask(
69-
functions[keys[i]][0] as IGlobalIndexedToken<GlobalFunctionToken>,
70-
structures[keys[i]][0] as IGlobalIndexedToken<GlobalStructureToken>,
71-
);
72-
}
44+
/** Register tasks that we have found */
45+
registry.registerTasksFromGlobalTokens(
46+
index.globalIndex.globalTokensByTypeByName[GLOBAL_TOKEN_TYPES.FUNCTION],
47+
index.globalIndex.globalTokensByTypeByName[GLOBAL_TOKEN_TYPES.STRUCTURE],
48+
);
7349

7450
// server.logManager.log({
7551
// log: IDL_MCP_LOG,

libs/mcp/server-tools/src/lib/tools/envi/register-mcp-tool-create-envi-modeler-workflow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ export function RegisterMCPTool_CreateENVIModelerWorkflow(
214214
edges as ENVIModelerEdge[],
215215
registry,
216216
);
217-
const modelContent = JSON.stringify(modelJSON, null, 4);
217+
const modelContent = JSON.stringify(modelJSON, null, 2);
218218

219219
// ---- write to disk
220220
try {

libs/mcp/tasks/src/lib/mcp-task-registry.class.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Ajv from 'ajv';
1212
import { z, ZodRawShape } from 'zod';
1313
import { zodToJsonSchema } from 'zod-to-json-schema';
1414

15+
import { FilterMCPENVITasks } from './helpers/filter-mcp-envi-tasks';
1516
import { GetCleanDescription } from './helpers/get-clean-description';
1617
import { StrictCheck } from './helpers/strict-check';
1718
import {
@@ -104,7 +105,7 @@ export class MCPTaskRegistry {
104105
/**
105106
* Gets information about a task
106107
*/
107-
getTaskDetail(taskName: string): ITaskInformation {
108+
getTaskDetail(taskName: string): ITaskInformation | undefined {
108109
/** Get lower case name */
109110
const lc = taskName.toLowerCase();
110111

@@ -296,6 +297,32 @@ export class MCPTaskRegistry {
296297
};
297298
}
298299

300+
/**
301+
* Loads tasks from global tokens (i.e. after we index a location)
302+
*/
303+
registerTasksFromGlobalTokens(
304+
functions: {
305+
[key: string]: IGlobalIndexedToken<GlobalFunctionToken>[];
306+
},
307+
structures: {
308+
[key: string]: IGlobalIndexedToken<GlobalStructureToken>[];
309+
},
310+
) {
311+
/** Find names of ENVI Tasks and exclude those we dont need to expose */
312+
const keys = FilterMCPENVITasks(functions, Object.keys(structures)).sort();
313+
314+
this.logger.log({
315+
log: IDL_MCP_LOG,
316+
type: 'info',
317+
content: `Attempting to register ${keys.length} ENVI Tools`,
318+
});
319+
320+
// add all ENVI Tasks
321+
for (let i = 0; i < keys.length; i++) {
322+
this.registerTask(functions[keys[i]][0], structures[keys[i]][0]);
323+
}
324+
}
325+
299326
/**
300327
* Remove a task from the registry
301328
*
@@ -356,7 +383,7 @@ export class MCPTaskRegistry {
356383
// check if we have JSON schema problems
357384
if (!valid) {
358385
// Format validation errors for the response
359-
const errors = validate.errors
386+
const errors = (validate.errors || [])
360387
.map(
361388
(err) =>
362389
`- ${err.instancePath || 'root'}: ${err.message}${

0 commit comments

Comments
 (0)