Skip to content

MCP should return empty instead of error if tools / prompts / resources are not defined #181

Open
@theodormarcu

Description

@theodormarcu

Describe the bug
Currently, if you set up a server with the tools defined, but no prompts / resources, attempting to get tools/resources will throw an error instead of returning empty.

To Reproduce
Steps to reproduce the behavior:

  1. Set up an MCP server + client
  2. Define a test tool
  3. Try calling listPrompts or listResources

Expected behavior

All list* methods (that return collections) should return empty arrays when there is nothing to return.

get* should throw an error.

Logs

Additional context

Returning an empty array is a idiomatic pattern when a collection of items is empty.

Express.js

When you query routes that don't match anything, Express returns a 404 rather than crashing
app.get('/api/items') will return an empty array [] when no items exist, not an error

React

When mapping over an empty array of items, React doesn't throw errors - it renders nothing
{items.map(item => <Component key={item.id} {...item} />)} works fine when items is empty

PostgreSQL / Sequelize

User.findAll() returns an empty array if no users exist
It only throws if the table itself doesn't exist (which would be a structural issue)

Next.js

getStaticPaths() can return an empty array if there are no dynamic routes
It doesn't error out because an empty set of paths is valid

Redux

Selectors return empty arrays or default values when querying state that doesn't exist
const todos = useSelector(state => state.todos || []) handles missing state gracefully

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions