Mocapi is a modular framework for building Model Context Protocol (MCP) tools and prompts using Spring Boot. It simplifies secure, structured interactions between LLMs and services via annotated Java components.
Mocapi includes a Spring Boot starter, making it easy to get started by simply adding a dependency:
<dependency>
<groupId>com.callibrity.mocapi</groupId>
<artifactId>mocapi-spring-boot-starter</artifactId>
<version>${mocapi.version}</version>
</dependency>By default, Mocapi will listen for MCP requests on the /mcp endpoint. You can change this by setting the ripcurl.endpoint property:
ripcurl.endpoint=/your-custom-endpointTo create MCP tools using Mocapi, you first need to import the mocapi-tools dependency into your project:
<dependency>
<groupId>com.callibrity.mocapi</groupId>
<artifactId>mocapi-tools</artifactId>
<version>${mocapi.version}</version>
</dependency>This will automatically activate the MocapiToolsAutoConfiguration which will enable MCP tools support. To register a
tool, you need to create a bean annotated with @ToolService having methods annotated with @Tool:
import com.callibrity.mocapi.tools.annotation.Tool;
import com.callibrity.mocapi.tools.annotation.ToolService;
import org.springframework.stereotype.Component;
@Component
@ToolService
public class HelloTool {
@Tool
public HelloResponse sayHello(String name) {
return new HelloResponse(String.format("Hello, %s!", name));
}
public record HelloResponse(String message) { }
}To create MCP prompts using Mocapi, you first need to import the mocapi-prompts dependency into your project:
<dependency>
<groupId>com.callibrity.mocapi</groupId>
<artifactId>mocapi-prompts</artifactId>
<version>${mocapi.version}</version>
</dependency>This will automatically activate the MocapiPromptsAutoConfiguration which will enable MCP prompts support. To register a
prompt, you need to create a bean annotated with @PromptService having methods annotated with @Prompt:
import com.callibrity.mocapi.prompts.GetPromptResult;
import com.callibrity.mocapi.prompts.PromptMessage;
import com.callibrity.mocapi.prompts.Role;
import com.callibrity.mocapi.prompts.annotation.Prompt;
import com.callibrity.mocapi.prompts.annotation.PromptService;
import com.callibrity.mocapi.prompts.content.TextContent;
import io.swagger.v3.oas.annotations.media.Schema;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
@PromptService
public class CodeReviewPrompts {
@Prompt(name = "review-code", description = "Provide a short review of the given code snippet")
public GetPromptResult reviewCode(String language, String code) {
var prompt = String.format("""
Please review the following %s code and suggest improvements:
```%s
%s
```
""", language, language, code);
return new GetPromptResult("Provide a short review of the given code snippet", List.of(
new PromptMessage(Role.USER, new TextContent(prompt))
));
}
}Mocapi includes an example application to demonstrate how to use the framework. To run it, follow these steps:
-
Navigate to the
mocapi-exampledirectory.cd mocapi-example -
Run the application using Maven:
mvn spring-boot:run
-
The application will start on port 8080 by default. You can access the example tools and prompts at the
/mcpendpoint.
You can interact with the example application using the MCP Inspector. To do this, follow these steps:
- Launch the MCP inspector by running the following command in your terminal:
npx @modelcontextprotocol/inspector
- Your browser will open the MCP Inspector interface. Enter the URL of the running example application (e.g.,
http://localhost:8080/mcp) in the URL field. - Select the "Streamable HTTP" transport option.
- Click "Connect" to establish a connection to the example application.
- You can now explore the available tools and prompts, send requests, and view responses directly in the MCP Inspector interface.
- Enjoy!
Mocapi is a made-up word that includes the letters MCP (Model Context Protocol). It’s pronounced moh-cap-ee (/ˈmoʊˌkæpi/), like a friendly little robot who speaks protocol.
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
To build the project yourself, simply clone the repository and use Apache Maven to compile and package it:
mvn clean installThis project is licensed under the Apache License 2.0—see the LICENSE file for details.