fix tool count issue

This commit is contained in:
saidsurucu
2025-07-21 20:46:54 +03:00
parent 1fbcb65031
commit 217103f0b6
2 changed files with 30 additions and 12 deletions
+11 -4
View File
@@ -57,8 +57,8 @@ if CLERK_SECRET_KEY and CLERK_ISSUER:
jwks_uri=f"{CLERK_ISSUER}/.well-known/jwks.json",
issuer=CLERK_ISSUER,
algorithm="RS256",
audience=CLERK_PUBLISHABLE_KEY, # Use publishable key as audience
required_scopes=["yargi.read"] # Global scope requirement
audience=None, # Disable audience validation - Clerk uses different audience format
required_scopes=[] # Disable scope validation - Clerk JWT has ['read', 'search']
)
logger.info(f"Bearer auth configured with Clerk JWKS: {CLERK_ISSUER}/.well-known/jwks.json")
else:
@@ -165,8 +165,15 @@ async def health_check():
"auth_enabled": os.getenv("ENABLE_AUTH", "false").lower() == "true"
})
# Mount MCP app at /mcp (not at root to avoid conflicts)
app.mount("/mcp", mcp_app)
# Add explicit redirect for /mcp to /mcp/ with method preservation
@app.api_route("/mcp", methods=["GET", "POST", "HEAD", "OPTIONS"])
async def redirect_to_slash(request: Request):
"""Redirect /mcp to /mcp/ preserving HTTP method with 308"""
from fastapi.responses import RedirectResponse
return RedirectResponse(url="/mcp/", status_code=308)
# Mount MCP app at /mcp/ with trailing slash
app.mount("/mcp/", mcp_app)
# Set the lifespan context after mounting
app.router.lifespan_context = mcp_app.lifespan
+19 -8
View File
@@ -240,12 +240,25 @@ from fastmcp import FastMCP
def create_app(auth=None):
"""Create FastMCP app with standard capabilities and optional auth."""
global app
if auth:
app = FastMCP("Yargı MCP Server", auth=auth)
# Replace placeholder app with auth-enabled app, keeping all tools/resources
auth_app = FastMCP("Yargı MCP Server", auth=auth)
# Copy all tools and resources from placeholder app to auth-enabled app
auth_app._tool_manager = app._tool_manager
auth_app._resource_manager = app._resource_manager
app = auth_app
logger.info("MCP server created with Bearer authentication enabled")
else:
app = FastMCP("Yargı MCP Server")
# Update placeholder app name
app.name = "Yargı MCP Server"
logger.info("MCP server created with standard capabilities (FastMCP handles tools.listChanged automatically)")
# Add token counting middleware
token_counter = TokenCountingMiddleware()
app.add_middleware(token_counter)
logger.info("Token counting middleware added to MCP server")
return app
# --- Module Imports ---
@@ -335,13 +348,11 @@ from bddk_mcp_module.models import (
)
# Create app without auth initially (auth will be added in ASGI wrapper)
app = create_app()
# Create a placeholder app that will be properly initialized after tools are defined
from fastmcp import FastMCP
# --- Add Token Counting Middleware ---
token_counter = TokenCountingMiddleware()
app.add_middleware(token_counter)
logger.info("Token counting middleware added to MCP server")
# Placeholder app for decorators - will be replaced in create_app() after all tools are defined
app = FastMCP("Yargı MCP Server Placeholder")
# --- Tool Documentation Resources ---
@app.resource("docs://tools/yargitay")