pass roles to mcp

This commit is contained in:
2025-12-08 19:02:12 +01:00
parent fbb050056f
commit 49ea3c1a99
8 changed files with 84 additions and 59 deletions

View File

@@ -17,10 +17,12 @@ export const POST = async (req: NextRequest) => {
// Get Auth0 session
const session = await auth0.getSession();
// Extract access token and roles from session
const accessToken = session?.accessToken;
// Extract roles from session
const userRoles = session?.user?.roles || [];
console.log("[copilotkit] session exists:", !!session);
console.log("[copilotkit] userRoles:", userRoles);
// 2. Create the CopilotRuntime instance with Auth0 configuration
const runtime = new CopilotRuntime({
agents: {
@@ -28,9 +30,8 @@ export const POST = async (req: NextRequest) => {
deploymentUrl: process.env.LANGGRAPH_DEPLOYMENT_URL || "http://localhost:8123",
graphId: "sample_agent",
langsmithApiKey: process.env.LANGSMITH_API_KEY || "",
langgraphConfig: {
configurable: {
auth0_access_token: accessToken,
assistantConfig: {
context: {
auth0_user_roles: userRoles,
}
}

View File

@@ -95,7 +95,7 @@ export default function CopilotKitPage() {
<div className="flex-1 flex justify-center py-8 px-2 overflow-hidden">
<div className="h-full w-full max-w-5xl flex flex-col">
<CopilotChat
instructions={"You are a knowledgeable caving assistant. Help users with all aspects of caving including cave exploration, safety, surveying techniques, cave locations, geology, equipment, history, conservation, and any other caving-related topics. Provide accurate, helpful, and safety-conscious information."}
instructions={"You are a knowledgeable caving assistant. Help users with all aspects of caving including cave exploration, safety, surveying techniques, cave locations, geology, equipment, history, conservation, and any other caving-related topics. Provide accurate, helpful, and safety-conscious information. CRITICAL: Always cite sources at the end of each response."}
labels={{
title: "AI Cartwright",
initial: "Hello! I'm here to help with anything related to caving. Ask me about caves, techniques, safety, equipment, or anything else caving-related!",

View File

@@ -1,7 +1,7 @@
import { Auth0Client, filterDefaultIdTokenClaims } from '@auth0/nextjs-auth0/server';
export const auth0 = new Auth0Client({
async beforeSessionSaved(session, idToken) {
async beforeSessionSaved(session) {
return {
...session,
user: {