(target: Server)
| 921 | * same handler logic that closes over module-level state. |
| 922 | */ |
| 923 | export function registerHandlers(target: Server): void { |
| 924 | target.setRequestHandler(ListToolsRequestSchema, async () => |
| 925 | withTrackedSessionActivity(async () => ({ tools: TOOLS })) |
| 926 | ); |
| 927 | |
| 928 | target.setRequestHandler(ListResourcesRequestSchema, async () => |
| 929 | withTrackedSessionActivity(async () => ({ resources: buildResources() })) |
| 930 | ); |
| 931 | |
| 932 | target.setRequestHandler(ReadResourceRequestSchema, async (request) => |
| 933 | withTrackedSessionActivity(async () => { |
| 934 | const uri = request.params.uri; |
| 935 | const explicitProjectPath = getProjectPathFromContextResourceUri(uri); |
| 936 | const explicitFullProjectPath = getProjectPathFromFullContextResourceUri(uri); |
| 937 | |
| 938 | if (explicitFullProjectPath) { |
| 939 | const selection = await resolveProjectSelector(explicitFullProjectPath); |
| 940 | if (!selection.ok) { |
| 941 | throw new Error(`Unknown project resource: ${uri}`); |
| 942 | } |
| 943 | |
| 944 | const project = selection.project; |
| 945 | await initProject(project.rootPath, watcherDebounceMs, { enableWatcher: true }); |
| 946 | setActiveProject(project.rootPath); |
| 947 | return { |
| 948 | contents: [ |
| 949 | { |
| 950 | uri: buildProjectFullContextResourceUri(project.rootPath), |
| 951 | mimeType: 'text/plain', |
| 952 | text: await generateFullCodebaseIntelligence(project) |
| 953 | } |
| 954 | ] |
| 955 | }; |
| 956 | } |
| 957 | |
| 958 | if (explicitProjectPath) { |
| 959 | const selection = await resolveProjectSelector(explicitProjectPath); |
| 960 | if (!selection.ok) { |
| 961 | throw new Error(`Unknown project resource: ${uri}`); |
| 962 | } |
| 963 | |
| 964 | const project = selection.project; |
| 965 | await initProject(project.rootPath, watcherDebounceMs, { enableWatcher: true }); |
| 966 | setActiveProject(project.rootPath); |
| 967 | return { |
| 968 | contents: [ |
| 969 | { |
| 970 | uri: buildProjectContextResourceUri(project.rootPath), |
| 971 | mimeType: 'text/plain', |
| 972 | text: await generateCodebaseIntelligence(project) |
| 973 | } |
| 974 | ] |
| 975 | }; |
| 976 | } |
| 977 | |
| 978 | if (isFullContextResourceUri(uri)) { |
| 979 | const project = await resolveProjectForResource(); |
| 980 | return { |
no test coverage detected