MCP ExplorerExplorer

Spring Ai Mcp Authorization Demo

@Kehrlannon 21 days ago
1 MIT
FreeCommunity
AI Systems
Demo for Spring AI MCP security integration with authorization flow.

Overview

What is Spring Ai Mcp Authorization Demo

spring-ai-mcp-authorization-demo is a demonstration project that showcases the integration of Spring AI with MCP security features, particularly focusing on authorization mechanisms.

Use cases

Use cases include applications that require user authentication to access AI-driven services, such as querying weather information for specific locations.

How to use

To use spring-ai-mcp-authorization-demo, set your Anthropic API key in the environment variable ‘ANTHROPIC_API_KEY’. Then, run the authorization-server on port 9000, followed by the MCP Server (mcp-weather-webmvc-server) and the MCP client app (mcp-sse-http-client or mcp-sse-webflux-client for reactive). Navigate to the appropriate localhost URL to interact with the application.

Key features

Key features include OAuth2 authentication, integration with the Anthropic model, and support for both traditional and reactive web applications using Spring AI.

Where to use

spring-ai-mcp-authorization-demo can be used in areas requiring secure access to AI services, such as weather data retrieval, where user authentication is necessary.

Content

Spring AI MCP Security demo

This repository showcases Spring AI MCP security integration.

Usage

Before starting, set your Anthropic key in the env var ANTHROPIC_API_KEY.

  1. Run the authorization-server project, it starts on port 9000
  2. Run the MCP Server (mcp-weather-webmvc-server)
  3. Run the MCP client Servlet app (mcp-sse-servlet-webflux-client)
  4. Navigate to http://localhost:8080/
  5. When you try to get the temperature for, say, Paris, you will be redirected to the auth-server on port 9000. Log in
    with user / password. Tadaa 🎉
    • there will be a nasty error in the console logs. This is expected, it’s from Spring Security’s OAuth2 internals.
  6. Subsequent calls will not require a login.

Notes on WebFlux

If you would like to build a fully reactive Spring AI app, you need to use WebFlux. Some changes to Spring AI are
required to get it to work.

You MUST use this exact build of Spring
AI: https://github.com/Kehrlann/spring-ai/tree/dgarnier/poc-propagate-reactive-context-to-mcp-async

You MUST use the Anthropic model.

  1. Run the authorization-server project, it starts on port 9000
  2. Run the MCP Server (mcp-weather-webmvc-server)
  3. Run the MCP client Reactive app (mcp-sse-webflux)
  4. Navigate to http://localhost:8081/
  5. When you try to get the temperature for, say, Paris, you will be redirected to the auth-server on port 9000. Log in
    with user / password. Tadaa 🎉
    • there will be a nasty error in the console logs. This is expected, it’s from Spring Security’s OAuth2 internals.
  6. Subsequent calls will not require a login.

Tools

No tools

Comments