You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
is there a way to propagate the token from authenticated RPC call to A2A Server agent to an MCP Server call via AI Service? #711
The A2A client Agent call to http://localhost:11001 gets authenticated successfully by the A2A Server Agent. The question is how i can propagate the same access token from the authenticated session along when the AI Service makes a call to the MCP server.
Essentially, i would like to understands what options there are to get the same access token from the RPC call being pass along to the MCP and get it injected via the Authorization header
Running a test results in this error. As the MCP call from the AI service does not gets authenticated hence the 401 error
jakarta.enterprise.inject.CreationException: Error creating synthetic bean [U9ADr3gmC8Sgw7Tk6HeTkK8tptU]: java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.RuntimeException: Unexpected status code: 401
at dev.langchain4j.mcp.client.McpClient_U9ADr3gmC8Sgw7Tk6HeTkK8tptU_Synthetic_Bean.create(Unknown Source)
at dev.langchain4j.mcp.client.McpClient_U9ADr3gmC8Sgw7Tk6HeTkK8tptU_Synthetic_Bean.create(Unknown Source)
... 25 more
Caused by: java.util.concurrent.ExecutionException: java.lang.RuntimeException: Unexpected status code: 401
at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396)
at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2096)
at dev.langchain4j.mcp.client.DefaultMcpClient.initialize(DefaultMcpClient.java:166)
... 32 more
Caused by: java.lang.RuntimeException: Unexpected status code: 401
at io.quarkiverse.langchain4j.mcp.runtime.http.QuarkusStreamableHttpMcpTransport.lambda$execute$8(QuarkusStreamableHttpMcpTransport.java:259)
at io.vertx.core.impl.future.FutureImpl$4.onSuccess(FutureImpl.java:176)
This issue is similar to #410 but instead of acquiring a new token running the authorization code flow out of band, propagate the same token used to authenticate the user against a protected A2A Server agent.
I think the route cause is that the JsonRPC call to the A2A Server agent endpoint (http://localhost:11001) does not create an instance of SecurityIdentity and AccessTokenCredential so if you try inject them as below, the objects will be null
this behavior is different as when the endpoint is a REST endpoint produced by a Rest resource class where injecting AccessTokenCredential will allow you to grab the access token follow a successful login
String token = accessToken.getToken();
And because the AccessTokenCredential beans instance is null as part of the RPC call, the extension quarkus-langchain4j-oidc-mcp-auth-provider will not be able to propagate the access token (add a custom Authorization header to the MCP call via the AI Service) because it relies on an instance of AccessTokenCredential from where to get the access token and it can't cause it's null so the MCP call will return 401 as the Authorization header is not set to a valid access token.
i have add few lines my A2AAgentExecutorProducer class to confirm the above
@ApplicationScoped
public final class WanakuAgentExecutorProducer {
@Inject private WanakuMcpAiService wanakuMcpAiService;
@Inject private AccessTokenCredential accessToken;
@Produces
public AgentExecutor agentExecutor() {
return new WanakuAgentExecutor(wanakuMcpAiService, accessToken);
}
private static class WanakuAgentExecutor implements AgentExecutor {
private final WanakuMcpAiService wanakuMcpAiService;
private final AccessTokenCredential accessToken;
WanakuAgentExecutor(final WanakuMcpAiService wanakuMcpAiService, AccessTokenCredential accessToken) {
this.wanakuMcpAiService = wanakuMcpAiService;
this.accessToken = accessToken;
}
@Override
public void execute(RequestContext context, AgentEmitter agentEmitter) throws A2AError {
//Get autenticated username
System.out.println("Is Authenticated: " + context.getCallContext().getUser().isAuthenticated());
System.out.println("Username: " + context.getCallContext().getUser().getUsername());
//Get Access token
System.out.println("Token: " + accessToken.getToken());
and this is the output
2026-03-07 11:19:41,478 INFO [io.a2a.server.config.DefaultValuesConfigProvider] (vert.x-eventloop-thread-0) Loaded 6 A2A default configuration values from 1 resource(s)
2026-03-07 11:19:41,479 INFO [io.a2a.server.util.async.AsyncExecutorProducer] (vert.x-eventloop-thread-0) Initializing async executor: corePoolSize=5, maxPoolSize=50, keepAliveSeconds=60, queueCapacity=100
Is Authenticated: true
Username: jdoe
2026-03-07 11:19:42,075 ERROR [io.a2a.server.requesthandlers.DefaultRequestHandler] (a2a-agent-executor-1) Agent execution threw unexpected RuntimeException for task c466d333-e206-43ae-b432-f94db4bae035
Exception in WanakuAgentExecutorProducer.java:51
49
50 //Get Access token
→ 51 System.out.println("Token: " + accessToken.getToken());
52
53 // extract the text from the message
: jakarta.enterprise.context.ContextNotActiveException: RequestScoped context was not active when trying to obtain a bean instance for a client proxy of PRODUCER_METHOD bean [class=io.quarkus.oidc.runtime.OidcTokenCredentialProducer, id=qPtfJ2z9Vcs78nLYoSxmBSZ461Y]
- you can activate the request context for a specific method using the @ActivateRequestContext interceptor binding
at io.quarkus.arc.impl.ClientProxies.notActive(ClientProxies.java:76)
at io.quarkus.arc.impl.ClientProxies.getSingleContextDelegate(ClientProxies.java:32)
at io.quarkus.oidc.OidcTokenCredentialProducer_ProducerMethod_currentAccessToken_LqZ323vwEzgoIJymPKn-DMYcc6w_ClientProxy.arc$delegate(Unknown Source)
at io.quarkus.oidc.OidcTokenCredentialProducer_ProducerMethod_currentAccessToken_LqZ323vwEzgoIJymPKn-DMYcc6w_ClientProxy.getToken(Unknown Source)
at org.acme.WanakuAgentExecutorProducer$WanakuAgentExecutor.execute(WanakuAgentExecutorProducer.java:51)
at io.a2a.server.requesthandlers.DefaultRequestHandler$2.run(DefaultRequestHandler.java:892)
at java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
at java.base/java.lang.Thread.run(Thread.java:1583)
This is an example of access token passed along as part of the RPC call after successfully login as jdoe user using OIDC scheme.
option 1: for the A2A java sdk extension to create instances of SecurityIdentity and AccessTokenCredential beans after successful authentication in the same way it is done with Rest Resources and let quarkus-langchain4j-oidc-mcp-auth-provider extension seamlessly propagate the token.
option 2: make the access token available to the RequestContext. Right now the RequestContext allows you to get things like username, isAuthenticated etc but not the access token
if i the access token was available through the RequestContext in the AgentExecutor.execute(RequestContext context, AgentEmitter agentEmitter) method i could pass it to a programmatic defined AI Service like this
changed the title [-]is there a way to propagate the token from authenticated RPC call to A2A Server agent to and MCP Server call via AI Service?[/-][+]is there a way to propagate the token from authenticated RPC call to A2A Server agent to an MCP Server call via AI Service?[/+]on Mar 7, 2026
option 1: for the A2A java sdk extension to create instances of SecurityIdentity and AccessTokenCredential beans after successful authentication in the same way it is done with Rest Resources and let quarkus-langchain4j-oidc-mcp-auth-provider extension seamlessly propagate the token.
For option 1 maybe you want to make a new test when #698(with PR #707) is fixed: in Quarkus the propagation of OIDC is made transparent to the user (e.g: when using @accesstoken) so it must be propagated with the Quarkus context which makes the PR possible.
yes transparent propagation is made possible in Quarkus already
@accesstoken (rest-client-oidc-token-propagation extension) annotation on a Rest Client propagates current login credentials
oidc-mcp-auth-provider extension propagates current login credentials when running an AI Service method.
Once a protected resource is annotated with for instance @authenticated, follow successful authentication, Quarkus creates an instance of SecurityIdenity (io.quarkus.security.identity.SecurityIdentity) which is required for the token propagation to work.
I agree with your statement as root cause: when the server handoff the execution to the agent executor, the opentelemetry context is not propagated and then is lost.
if the context gets propagated to the Internal A2A executor, my issue will go away. i will retest after PR #707 is merged.
Thanks a lot @vietk, this is quite key feature to have to be able to implement remote A2A agent/MCP communication successful and securely, otherwise without the context identity calling MCP tools would make very difficult to producionize it and for your piece to consolidate traces under the same context identity/session.
Amazing, it does work after applying the fixes implemented a part of PR 707
the current access token gets picked up and propagated transparently when the AI Service calls the MCP Server endpoint which gets authenticated successfully.
@vietk I can't really thank you enough for helping out with this.
Activity
mescaja commentedon Mar 6, 2026
This issue is similar to #410 but instead of acquiring a new token running the authorization code flow out of band, propagate the same token used to authenticate the user against a protected A2A Server agent.
mescaja commentedon Mar 7, 2026
I think the route cause is that the JsonRPC call to the A2A Server agent endpoint (http://localhost:11001) does not create an instance of SecurityIdentity and AccessTokenCredential so if you try inject them as below, the objects will be null
@Inject AccessTokenCredential accessToken;
@Inject SecurityIdentity securityIdentity;
this behavior is different as when the endpoint is a REST endpoint produced by a Rest resource class where injecting AccessTokenCredential will allow you to grab the access token follow a successful login
String token = accessToken.getToken();
And because the AccessTokenCredential beans instance is null as part of the RPC call, the extension quarkus-langchain4j-oidc-mcp-auth-provider will not be able to propagate the access token (add a custom Authorization header to the MCP call via the AI Service) because it relies on an instance of AccessTokenCredential from where to get the access token and it can't cause it's null so the MCP call will return 401 as the Authorization header is not set to a valid access token.
i have add few lines my A2AAgentExecutorProducer class to confirm the above
and this is the output
This is an example of access token passed along as part of the RPC call after successfully login as jdoe user using OIDC scheme.
eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJHRmxqcFdyZjBodFR5QndLMU93TWFkLUpBcm5KTG11RERsV0lSMTc3VEwwIn0.eyJleHAiOjE3NzI4ODI2ODEsImlhdCI6MTc3Mjg4MjM4MSwianRpIjoib25ydHJvOjE1OWRmMzU5LWMwMmYtNzFmYS1kNTExLThlNzQ4N2FhMDJmOSIsImlzcyI6Imh0dHBzOi8va2V5Y2xvYWsucG9jL3JlYWxtcy93YW5ha3UiLCJhdWQiOlsid2FuYWt1LW1jcC1jbGllbnQiLCJhY2NvdW50Il0sInN1YiI6ImI2NWQ1NjViLTA1OTgtNDg3MS04NjU4LTM0MGNiODI1ODYxNiIsInR5cCI6IkJlYXJlciIsImF6cCI6IndhbmFrdS1zZXJ2aWNlIiwic2lkIjoiQU9mLWJGM0RPZTVOQ3g3bVpKZm9UYmJNIiwiYWNyIjoiMSIsImFsbG93ZWQtb3JpZ2lucyI6WyJodHRwOi8vbG9jYWxob3N0OjgwODAvKiIsIioiXSwicmVhbG1fYWNjZXNzIjp7InJvbGVzIjpbIm9mZmxpbmVfYWNjZXNzIiwiZGVmYXVsdC1yb2xlcy13YW5ha3UiLCJ1bWFfYXV0aG9yaXphdGlvbiIsIlRlc3RpbmciXX0sInJlc291cmNlX2FjY2VzcyI6eyJhY2NvdW50Ijp7InJvbGVzIjpbIm1hbmFnZS1hY2NvdW50IiwibWFuYWdlLWFjY291bnQtbGlua3MiLCJ2aWV3LXByb2ZpbGUiXX19LCJzY29wZSI6ImVtYWlsIHdhbmFrdS1tY3AtY2xpZW50IHBob25lIHByb2ZpbGUiLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwibmFtZSI6Impkb2UgZm4gamRvZSBsbiIsInByZWZlcnJlZF91c2VybmFtZSI6Impkb2UiLCJnaXZlbl9uYW1lIjoiamRvZSBmbiIsImZhbWlseV9uYW1lIjoiamRvZSBsbiIsImVtYWlsIjoiamRvZUBrZXljbG9hay5jb20ifQ.LpgC4a3UtQG0TEJe0GB6bd0hJtBPirtwpN-BFZsTLO0Lqfska4toqF3mjLGUkzkgmdwEuIf0nvRXnRb0lGueNX_ZazT4okf9GWJ1zKdhgOMiAFirBR-3PONQmE4hXm6lu7C2wgHL6uoaVCudeasxoQnINvesnj2m1yHCVDjsXFhpu6dK1uZocexQhZR8veg1TUa2tYYakr_ScEgIa4lDkBsYtMdaGu1cSNHRk7NZHhlgP89dFXY-fyIhZL7NNiG99YZMFRhk36jy3b50NyNFYGGDBNWpuJFavOPgUBEyr9yiwSO42cAuOGHq4SwnHr8w-_Q26M7zVJsqSifxk_xWcAmescaja commentedon Mar 7, 2026
I guess there are 2 options
option 1: for the A2A java sdk extension to create instances of SecurityIdentity and AccessTokenCredential beans after successful authentication in the same way it is done with Rest Resources and let quarkus-langchain4j-oidc-mcp-auth-provider extension seamlessly propagate the token.
option 2: make the access token available to the RequestContext. Right now the RequestContext allows you to get things like username, isAuthenticated etc but not the access token
if i the access token was available through the RequestContext in the AgentExecutor.execute(RequestContext context, AgentEmitter agentEmitter) method i could pass it to a programmatic defined AI Service like this
mescaja commentedon Mar 7, 2026
this is by the way the confguration on the A2A Server agent quarkus app that protects http://localhost:11001/ endpoint using quarkus OIDC extension
[-]is there a way to propagate the token from authenticated RPC call to A2A Server agent to and MCP Server call via AI Service?[/-][+]is there a way to propagate the token from authenticated RPC call to A2A Server agent to an MCP Server call via AI Service?[/+]vietk commentedon Mar 8, 2026
Hello,
For option 1 maybe you want to make a new test when #698(with PR #707) is fixed: in Quarkus the propagation of OIDC is made transparent to the user (e.g: when using @accesstoken) so it must be propagated with the Quarkus context which makes the PR possible.
mescaja commentedon Mar 9, 2026
yes transparent propagation is made possible in Quarkus already
Once a protected resource is annotated with for instance @authenticated, follow successful authentication, Quarkus creates an instance of SecurityIdenity (io.quarkus.security.identity.SecurityIdentity) which is required for the token propagation to work.
I agree with your statement as root cause: when the server handoff the execution to the agent executor, the opentelemetry context is not propagated and then is lost.
if the context gets propagated to the Internal A2A executor, my issue will go away. i will retest after PR #707 is merged.
Thanks a lot @vietk, this is quite key feature to have to be able to implement remote A2A agent/MCP communication successful and securely, otherwise without the context identity calling MCP tools would make very difficult to producionize it and for your piece to consolidate traces under the same context identity/session.
mescaja commentedon Mar 11, 2026
Amazing, it does work after applying the fixes implemented a part of PR 707
the current access token gets picked up and propagated transparently when the AI Service calls the MCP Server endpoint which gets authenticated successfully.
@vietk I can't really thank you enough for helping out with this.
vietk commentedon Mar 12, 2026
all credits goes to @ehsavoie, he found a better idea than I had with using the Quarkus ExecutorService.