Skip to main content
Glama
DivyamAgg24

Spotify-Claude MCP Server

by DivyamAgg24

get_artist

Retrieve artist information from Spotify to enhance music discovery through natural language queries.

Instructions

Get Artist name

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
methodYesGet or post request

Implementation Reference

  • The handler function for the 'get_artist' tool. It fetches artist data from the Spotify API using the provided HTTP method, processes the response, extracts artist names, and returns them in a text content block.
    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,
            },
        ],
        };
    },
  • Input schema defined using Zod, specifying a 'method' parameter as a string with minimum length 3.
    {
      method: z.string().min(3).describe("Get or post request")
    },
  • src/index.ts:15-69 (registration)
    Registration of the 'get_artist' tool on the MCP server, 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,
                },
            ],
            };
        },
    )

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/DivyamAgg24/SpotifyMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server