Get startedGet started for free

Search for a Book by Title with the Open Library MCP

The Open Library MCP exposes tools that query the Internet Archive's Open Library API. In this exercise you will connect to the server, initialize a session, and use the get_book_by_title tool to search for a book and print the result.

Because of the unique setup of DataCamp exercises, the command and args set in StdioServerParameters() differ from those shown in the video and what you would use locally, but the principle is the same: the server is being spun up from the installed source files.

This exercise is part of the course

Introduction to Model Context Protocol (MCP)

View Course

Exercise instructions

  • Call the get_book_by_title tool to search for book titles containing "AI" and assign the result to result.
  • Assign the result text from result.content[0].text to text and print it.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client

async def main():
    params = StdioServerParameters(command=OPEN_LIBRARY_SERVER_CMD, args=OPEN_LIBRARY_SERVER_ARGS)
    async with stdio_client(params) as (reader, writer):
        async with ClientSession(reader, writer) as session:
            await session.initialize()
            # Call get_book_by_title for "AI" and assign the result
            result = await session.call_tool(____, {"title": "____"})
            # Assign the result text and print it
            text = result.content[0].____
            print(text)

asyncio.run(main())
Edit and Run Code