Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for MCP (Model Context Protocol) #6179

Open
Dogacel opened this issue Mar 28, 2025 · 4 comments
Open

Support for MCP (Model Context Protocol) #6179

Dogacel opened this issue Mar 28, 2025 · 4 comments

Comments

@Dogacel
Copy link
Contributor

Dogacel commented Mar 28, 2025

From, https://modelcontextprotocol.io/introduction

MCP is an open protocol that standardizes how applications provide context to LLMs. Think of MCP like a USB-C port for AI applications. Just as USB-C provides a standardized way to connect your devices to various peripherals and accessories, MCP provides a standardized way to connect AI models to different data sources and tools.

This protocol is relatively new and there is a lot of hype around it. I think there is value in creating an experimental module to add MCP support in Armeria. I think it can boost the project's popularity as well.

For example, Http4k added it recently: https://www.http4k.org/news/http4k_mcp_has_landed/
And Spring boot: https://docs.spring.io/spring-ai-mcp/reference/overview.html

As current implementation of MCP uses SSE, it should be relatively easy to abstract out the MCP protocol as a separate HttpService.

@Dogacel
Copy link
Contributor Author

Dogacel commented Mar 28, 2025

If you find value in this project, I am willing to pair-up to help. I have recently went ahead and helped a relatively new CLI tools for interacting MCPs to add HTTP support, so I am kinda familiar with the protocol now.

@ikhoon
Copy link
Contributor

ikhoon commented Mar 31, 2025

I am also interested in MCP. It would be awesome if we could support MCP in Armeria.

@Dogacel
Copy link
Contributor Author

Dogacel commented Mar 31, 2025

I am also interested in MCP. It would be awesome if we could support MCP in Armeria.

Here are some suggestions.

public class MyMcpService implements McpService {
  @Override
  public Set<McpTool> tools() { ... }

  @Override
  public Set<McpResource> resources() { ... }

  @Override
  public Set<McpPrompt> prompts() { ... }
}

public class TellAgeTool implements McpTool {
  @Override public String name = "tell-age";
  @Override public String description = "Tells the age of a person";

  @Override
  public McpParams params() {
     return McpParams.of(
        McpParams.string("name"),
        McpParams.int("age").withDescription("Age of the person"),
     );
  }

  @Override
  public ToolResponse handle(McpParams params) {
    String name = params.string("name");
    Int age = params.int("age").orDefault(0);
    
    return ToolResponse.ofText("Hello " + name ", you are " + age + " years old.");
  }
}

public class PersonResource implements McpResource {
  @Override public String name = "person";
  @Override public String uri = "uri://person";

  @Override
  public ResourceResponse handle(params: McpParams) {
    URI uri = params.uri("uri");
     
    return ResourceResponse.ofImage(Images.get(uri).toBase64());
  } 
}

public class SamplePrompt implements McpPrompt {
   @Override public String name = "person";

   @Override
   public ResourceResponse handle(params: McpParams) {
     URI uri = params.uri("uri");
       
     return ResourceResponse.ofImage(Images.get(uri).toBase64());
   } 
}

sb.serviceUnder("/mcp", MyMcpService())

For registering the entities, we can also use annotations,

@McpService
public class MyMcpService {

  // Auto-register schema from parameters
  @Tool(name = "tellAge", description = "...")
  public tellAge(
     String name,
     Int age,
  ) ToolResponse {
     return ToolResponse.ofText("Hello " + name ", you are " + age + " years old.);
  }
  
  @Resource(uri = "file://person", name = "person", description = "...")
  public person(ResourceParams params) ResourceResponse {
    return ResourceResponse.ofImage(Images.get(params.uri).toBase64());
  }


  @Prompt()
  public prompt(
    String code
  ) PromptResponse {
     return PromptResponse.ofResource("uri://...");
  }
}

sb.mcpService("/mcp", MyMcpService())
// Or
sb.annotatedService("/mcp", MyMcpService())

@codefromthecrypt
Copy link
Contributor

I would like this, even though it is an interesting challenge for trace propagation. Suggest we support stdio mode as well, even though that isn't typical for armeria. Rationale is well engineered i/o is a win even if using stdio.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants