Skip to content

Commit b9500d7

Browse files
committed
fix: better error handling and code dedupe
1 parent deb4046 commit b9500d7

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

src/resources.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ export async function fetchRawGithubContent(rawPath: string) {
66

77
const response = await fetch(`https://raw.githubusercontent.com${path}`);
88
if (!response.ok) {
9-
throw new Error(`Failed to fetch GitHub content: ${response.status}`);
9+
throw new Error(
10+
`Failed to fetch GitHub content: ${response.status} ${response.statusText}`,
11+
);
1012
}
1113
return response.text();
1214
}

src/tools/definitions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -924,12 +924,12 @@ export const NEON_TOOLS = [
924924
Loads comprehensive Neon documentation and usage guidelines from GitHub. This tool provides instructions for various Neon features and workflows.
925925
926926
Use this tool when:
927-
- User says "Get started with Neon" or similar onboarding phrases (with getStarted subject)
928-
- User needs detailed guidance for initial Neon setup and configuration (with getStarted subject)
929-
- You need comprehensive context about Neon workflows and best practices (with getStarted subject)
927+
- User says "Get started with Neon" or similar onboarding phrases (with neon-get-started subject)
928+
- User needs detailed guidance for initial Neon setup and configuration (with neon-get-started subject)
929+
- You need comprehensive context about Neon workflows and best practices (with neon-get-started subject)
930930
931931
Available subjects:
932-
- getStarted: Comprehensive interactive guide covering organization/project setup, database configuration, connection strings, dependency installation, schema creation/migration, etc.
932+
- neon-get-started: Comprehensive interactive guide covering organization/project setup, database configuration, connection strings, dependency installation, schema creation/migration, etc.
933933
</use_case>
934934
935935
<important_notes>

src/tools/tools.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { handleProvisionNeonAuth } from './handlers/neon-auth.js';
1515
import { handleSearch } from './handlers/search.js';
1616
import { handleFetch } from './handlers/fetch.js';
1717
import { getMigrationFromMemory, persistMigrationToMemory } from './state.js';
18-
import { fetchRawGithubContent } from '../resources.js';
18+
import { fetchRawGithubContent, NEON_RESOURCES } from '../resources.js';
1919

2020
import {
2121
getDefaultDatabase,
@@ -1016,17 +1016,23 @@ async function handleListSharedProjects(
10161016
}
10171017

10181018
async function handleLoadResource({ subject }: { subject: string }) {
1019-
const resourceMap = {
1020-
getStarted: '/neondatabase-labs/ai-rules/blob/main/neon-get-started.mdc',
1021-
};
1022-
1023-
const path = resourceMap[subject as keyof typeof resourceMap];
1024-
if (!path) {
1025-
throw new InvalidArgumentError(`Unknown resource subject: ${subject}`);
1019+
const resource = NEON_RESOURCES.find((r) => r.name === subject);
1020+
if (!resource) {
1021+
throw new InvalidArgumentError(`Resource not found: ${subject}`);
10261022
}
10271023

1028-
const content = await fetchRawGithubContent(path);
1029-
return content;
1024+
try {
1025+
const url = new URL(resource.uri);
1026+
const path = url.pathname;
1027+
const content = await fetchRawGithubContent(path);
1028+
return content;
1029+
} catch (error) {
1030+
const errorMessage =
1031+
error instanceof Error ? error.message : 'Unknown error';
1032+
throw new Error(
1033+
`Failed to load resource "${resource.name}": ${errorMessage}`,
1034+
);
1035+
}
10301036
}
10311037

10321038
async function handleCompareDatabaseSchema(

src/tools/toolsSchema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,8 @@ export const fetchInputSchema = z.object({
361361

362362
export const loadResourceInputSchema = z.object({
363363
subject: z
364-
.enum(['getStarted'])
364+
.enum(['neon-get-started'])
365365
.describe(
366-
'The subject of the resource to load. Options: getStarted (Neon getting started guide).',
366+
'The subject of the resource to load. Options: neon-get-started (Neon getting started guide).',
367367
),
368368
});

0 commit comments

Comments
 (0)