get_artist
Retrieve artist names from Spotify to enhance music discovery via natural language queries on the Claude platform. Supports GET/POST requests for streamlined data access.
Instructions
Get Artist name
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| method | Yes | Get or post request |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"method": {
"description": "Get or post request",
"minLength": 3,
"type": "string"
}
},
"required": [
"method"
],
"type": "object"
}
Implementation Reference
- src/index.ts:21-68 (handler)Handler function that fetches artist data from Spotify API using the provided HTTP method, processes the response, extracts artist names, and returns them in a text content format.async ({ method }) => { const methodUpper = method.toUpperCase(); const artistData = await fetch("https://api.spotify.com/v1/artists?ids=0TnOYISbd1XYRBk9myaseg", { headers: { Authorization: `Bearer ${accessToken}`, }, method }) if (!artistData) { return { content: [ { type: "text", text: "Failed to retrieve tracks", }, ], }; } const allArtistsData = await artistData.json() console.log(allArtistsData) const data = allArtistsData.artists || []; if (data.length===0) { return { content: [ { type: "text", text: `No artists`, }, ], }; } let names = [] for(let i = 0; i<data.length; i++){ names.push(data[i].name) } const finalOutput = `Artist name is ${names}`; return { content: [ { type: "text", text: finalOutput, }, ], }; },
- src/index.ts:18-20 (schema)Zod schema defining the input parameter 'method' as a string with minimum length 3, described as 'Get or post request'.{ method: z.string().min(3).describe("Get or post request") },
- src/index.ts:15-69 (registration)Registration of the 'get_artist' tool using server.tool(), including name, description, input schema, and handler function.server.tool( "get_artist", "Get Artist name", { method: z.string().min(3).describe("Get or post request") }, async ({ method }) => { const methodUpper = method.toUpperCase(); const artistData = await fetch("https://api.spotify.com/v1/artists?ids=0TnOYISbd1XYRBk9myaseg", { headers: { Authorization: `Bearer ${accessToken}`, }, method }) if (!artistData) { return { content: [ { type: "text", text: "Failed to retrieve tracks", }, ], }; } const allArtistsData = await artistData.json() console.log(allArtistsData) const data = allArtistsData.artists || []; if (data.length===0) { return { content: [ { type: "text", text: `No artists`, }, ], }; } let names = [] for(let i = 0; i<data.length; i++){ names.push(data[i].name) } const finalOutput = `Artist name is ${names}`; return { content: [ { type: "text", text: finalOutput, }, ], }; }, )