Skip to content

Commit b9ab5f9

Browse files
committed
Make get_started more generic
1 parent cb0f17b commit b9ab5f9

File tree

1 file changed

+83
-90
lines changed

1 file changed

+83
-90
lines changed

src/tools/index.ts

Lines changed: 83 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -155,108 +155,101 @@ export function shopifyTools(server: McpServer) {
155155
},
156156
);
157157

158-
if (process.env.POLARIS_UNIFIED) {
159-
server.tool(
160-
"read_polaris_surface_docs",
161-
`Use this tool to retrieve a list of documents from shopify.dev.
158+
server.tool(
159+
"read_docs",
160+
`Use this tool to retrieve a list of documents from shopify.dev.
162161
163-
Args:
164-
paths: The paths to the documents to read, in a comma separated list.
165-
Paths should be relative to the root of the developer documentation site.`,
166-
{
167-
paths: z
168-
.array(z.string())
169-
.describe("The paths to the documents to read"),
170-
},
171-
async ({ paths }) => {
172-
async function fetchDocText(path: string): Promise<{
173-
text: string;
174-
path: string;
175-
success: boolean;
176-
}> {
177-
try {
178-
const appendedPath = path.endsWith(".txt") ? path : `${path}.txt`;
179-
const url = new URL(appendedPath, SHOPIFY_BASE_URL);
180-
const response = await fetch(url.toString());
181-
const text = await response.text();
182-
return { text: `## ${path}\n\n${text}\n\n`, path, success: true };
183-
} catch (error) {
184-
return {
185-
text: `Error fetching document at ${path}: ${error}`,
186-
path,
187-
success: false,
188-
};
189-
}
162+
Args:
163+
paths: The paths to the documents to read, in a comma separated list.
164+
Paths should be relative to the root of the developer documentation site.`,
165+
{
166+
paths: z
167+
.array(z.string())
168+
.describe("The paths to the documents to read"),
169+
},
170+
async ({ paths }) => {
171+
async function fetchDocText(path: string): Promise<{
172+
text: string;
173+
path: string;
174+
success: boolean;
175+
}> {
176+
try {
177+
const appendedPath = path.endsWith(".txt") ? path : `${path}.txt`;
178+
const url = new URL(appendedPath, SHOPIFY_BASE_URL);
179+
const response = await fetch(url.toString());
180+
const text = await response.text();
181+
return { text: `## ${path}\n\n${text}\n\n`, path, success: true };
182+
} catch (error) {
183+
return {
184+
text: `Error fetching document at ${path}: ${error}`,
185+
path,
186+
success: false,
187+
};
190188
}
189+
}
191190

192-
const fetchDocs = paths.map((path) => fetchDocText(path));
193-
const results = await Promise.all(fetchDocs);
194-
195-
return {
196-
content: [
197-
{
198-
type: "text" as const,
199-
text: results.map(({ text }) => text).join("---\n\n"),
200-
},
201-
],
202-
};
203-
},
204-
);
205-
206-
const surfaces = [
207-
"app-home",
208-
"admin-extensions",
209-
"checkout-extensions",
210-
"customer-account-extensions",
211-
] as const;
212-
server.tool(
213-
"get_started",
214-
`
215-
1. Ask user for the surface they are building for.
216-
2. Use read_polaris_surface_docs tool to read the docs for the surface.
191+
const fetchDocs = paths.map((path) => fetchDocText(path));
192+
const results = await Promise.all(fetchDocs);
217193

218-
Whenever the user asks about Polaris web components, always use this tool first to provide the most accurate and up-to-date documentation.
194+
return {
195+
content: [
196+
{
197+
type: "text" as const,
198+
text: results.map(({ text }) => text).join("---\n\n"),
199+
},
200+
],
201+
};
202+
},
203+
);
219204

220-
valid arguments for this tool are:
221-
- "app-home"
222-
- "admin-extensions"
223-
- "checkout-extensions"
224-
- "customer-account-extensions"
205+
const surfaces = [
206+
...(process.env.POLARIS_UNIFIED ? ["app-ui"] : []),
207+
"admin",
208+
"functions",
209+
]
225210

226-
Once you determine the surface, you should then use the read_polaris_surface_docs tool to learn about more specific details. Overviews are not comprehensive, so this is important.
211+
const surfaceDescriptions: Record<string, string> = {
212+
"app-ui": "App Home, Admin Extensions, Checkout Extensions, Customer Account Extensions, Polaris Web Components",
213+
"admin": "Admin API, Admin API GraphQL Schema, Admin API REST Schema",
214+
"functions": "Shopify Functions, Shopify Functions API",
215+
};
227216

228-
DON'T SEARCH THE WEB WHEN REFERENCING INFORMATION FROM THIS DOCUMENTATION. IT WILL NOT BE ACCURATE. ONLY USE THE read_polaris_surface_docs TOOLS TO RETRIEVE INFORMATION FROM THE DEVELOPER DOCUMENTATION SITE.
229-
`,
230-
{
231-
surface: z
232-
.enum(surfaces)
233-
.describe("The Shopify surface you are building for"),
234-
},
235-
async function cb({ surface }) {
236-
if (!surfaces.includes(surface)) {
237-
const options = surfaces.map((s) => `- ${s}`).join("\n");
238-
const text = `Please specify which Shopify surface you are building for. Valid options are: ${options}.`;
217+
server.tool(
218+
"get_started",
219+
`
220+
Use this tool first whenever you're interacting with any of these Shopify surfaces.
239221
240-
return {
241-
content: [{ type: "text" as const, text }],
242-
};
243-
}
222+
Valid arguments for \`surface\` are:
223+
${surfaces.map(surface => ` - ${surface}: ${surfaceDescriptions[surface]}`).join('\n')}
244224
245-
const docEntrypointsBySurface: Record<string, string> = {
246-
"app-home": "/docs/api/app-home/using-polaris-components",
247-
"admin-extensions": "/docs/api/admin-extensions",
248-
"checkout-extensions": "/docs/api/checkout-ui-extensions",
249-
"customer-account-extensions":
250-
"/docs/api/customer-account-ui-extensions",
251-
};
225+
1. Look at the getting started guide for the surface.
226+
2. Use read_docs tool to read additional docs for the surface.
252227
253-
const docPath = docEntrypointsBySurface[surface];
254-
const text = await fetchDocText(docPath);
228+
DON'T SEARCH THE WEB WHEN REFERENCING INFORMATION FROM THIS DOCUMENTATION. IT WILL NOT BE ACCURATE. ONLY USE THE read_docs TOOLS TO RETRIEVE INFORMATION FROM THE DEVELOPER DOCUMENTATION SITE.
229+
`,
230+
{
231+
surface: z
232+
.enum(surfaces as any)
233+
.describe("The Shopify surface you are building for"),
234+
},
235+
async function cb({ surface }) {
236+
if (!surfaces.includes(surface)) {
237+
const options = surfaces.map((s) => `- ${s}`).join("\n");
238+
const text = `Please specify which Shopify surface you are building for. Valid options are: ${options}.`;
255239

256240
return {
257241
content: [{ type: "text" as const, text }],
258242
};
259-
},
260-
);
261-
}
243+
}
244+
245+
const response = await fetch(
246+
`${SHOPIFY_BASE_URL}/mcp/getting_started?surface=${surface}`,
247+
);
248+
const text = await response.text();
249+
250+
return {
251+
content: [{ type: "text" as const, text }],
252+
};
253+
},
254+
);
262255
}

0 commit comments

Comments
 (0)