mcp-server-example

Emircan-Kirez/mcp-server-example

3.2

If you are the rightful owner of mcp-server-example and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

This project demonstrates how to build an MCP (Model Context Protocol) Server with STDIO transport using Spring.

Tools
  1. get_all_users

    Retrieves a list of all users in the system.

  2. get_user_by_id

    Fetches detailed information about a user by their unique ID.

  3. get_username_by_id

    Returns only the username of a specific user based on their ID.

  4. get_user_by_phone

    Finds and returns user information using their phone number.

  5. get_accounts_by_user_id

    Retrieves all account records associated with a given user ID.

MCP Server Example

This project demonstrates how to build an MCP (Model Context Protocol) Server with STDIO transport using Spring.

๐Ÿ› ๏ธ Tool Services

This project includes two service classes that provide various tools accessible through the MCP Server. Each service encapsulates a specific set of tools related to either users or accounts.


๐Ÿ‘ค UserTools Service

This service contains tools related to user operations. It includes the following four tools:

  • get_all_users
    Retrieves a list of all users in the system.

  • get_user_by_id
    Fetches detailed information about a user by their unique ID.

  • get_username_by_id
    Returns only the username of a specific user based on their ID.

  • get_user_by_phone
    Finds and returns user information using their phone number.


๐Ÿ’ผ AccountTools Service

This service includes tools related to user account operations. It currently provides the following tool:

  • get_accounts_by_user_id
    Retrieves all account records associated with a given user ID.

๐Ÿ—๏ธ Building the Project

To build the project without running tests, use the following command:

./mvnw clean install -DskipTests

This will compile the code and package the application as a JAR file, skipping any test executions. The output JAR file will be located in the target/ directory.

โš™๏ธ Claude Desktop Configuration

To use this MCP server with Claude Desktop, you need to edit your claude_desktop_config.json file.

Add the following entry to your configuration:

{
  "user-mcp-server": {
    "command": "java",
    "args": [
      "-jar",
      "/absolute/path/to/target/mcp-server-example-0.0.1-SNAPSHOT.jar"
    ],
    "env": {
      "USER_SERVICE_URL": "https://jsonplaceholder.typicode.com/users"
    }
  }
}

Replace /absolute/path/to/ with the actual path to your built jar file.

๐Ÿ“Œ Sample Questions and Responses

  • โ“ Question
  • ๐Ÿ› ๏ธ Used Tool
  • ๐Ÿ’ฌ Response

โ“How many users do we have?

๐Ÿ› ๏ธ get_all_users

๐Ÿ’ฌ You have 10 users in your system.


โ“ Find me the user whose phone number is 1-770-736-8031 x56442

๐Ÿ› ๏ธ get_user_by_phone

๐Ÿ’ฌ I found the user with phone number 1-770-736-8031 x56442:

Name: Leanne Graham
ID: 1
Username: Bret
Email:
Phone: 1-770-736-8031 x56442
Website: hildegard.org
Address: Kulas Light, Apt. 556, Gwenborough, 92998-3874


โ“ Calculate the total balance for the user whose ID is 3 and give me the average balance for accounts

๐Ÿ› ๏ธ get_accounts_by_user_id get_user_by_id

๐Ÿ’ฌ Here are the account details for Clementine Bauch (User ID: 3):

Individual Account Balances:

  • Account ID 5: $3,000.00
  • Account ID 6: $2,500.00
  • Account ID 7: $400.00

Total Balance Across All Accounts: $5,900.00

Average Balance Per Account: $1,966.67 (Total: $5,900 รท 3 accounts = $1,966.67)