-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix integration tests for roots/list
#1119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,14 +7,17 @@ | |
| import java.io.IOException; | ||
| import java.net.InetSocketAddress; | ||
| import java.net.ServerSocket; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
|
|
||
| import jakarta.servlet.Filter; | ||
| import jakarta.servlet.Servlet; | ||
| import jakarta.servlet.ServletConfig; | ||
| import jakarta.servlet.ServletException; | ||
| import jakarta.servlet.ServletRequest; | ||
| import jakarta.servlet.ServletResponse; | ||
| import jakarta.servlet.http.HttpServletRequest; | ||
| import org.apache.catalina.Context; | ||
| import org.apache.catalina.Wrapper; | ||
| import org.apache.catalina.startup.Tomcat; | ||
| import org.apache.tomcat.util.descriptor.web.FilterDef; | ||
| import org.apache.tomcat.util.descriptor.web.FilterMap; | ||
|
|
@@ -41,7 +44,7 @@ public static Tomcat createTomcatServer(String contextPath, int port, Servlet se | |
| Context context = tomcat.addContext(contextPath, baseDir); | ||
|
|
||
| // Add transport servlet to Tomcat | ||
| org.apache.catalina.Wrapper wrapper = context.createWrapper(); | ||
| Wrapper wrapper = context.createWrapper(); | ||
| wrapper.setName("mcpServlet"); | ||
| wrapper.setServlet(servlet); | ||
| wrapper.setLoadOnStartup(1); | ||
|
|
@@ -78,12 +81,18 @@ public static class DelegatingServlet implements Servlet { | |
|
|
||
| private volatile Servlet delegate; | ||
|
|
||
| // Crude way of tracking whether a GET SSE stream has been | ||
| // established, to ensure a Streamable HTTP MCP Client is | ||
| // connected. | ||
| private final AtomicBoolean sseStreamEstablished = new AtomicBoolean(false); | ||
|
|
||
| /** | ||
| * Sets the servlet handling subsequent requests. The delegate is not | ||
| * {@link Servlet#init(ServletConfig) initialized}, since the MCP servlet | ||
| * transports do not rely on their {@link ServletConfig}. | ||
| */ | ||
| public void setDelegate(Servlet delegate) { | ||
| this.sseStreamEstablished.set(false); | ||
| this.delegate = delegate; | ||
| } | ||
|
|
||
|
|
@@ -104,6 +113,9 @@ public void service(ServletRequest request, ServletResponse response) throws Ser | |
| throw new IllegalStateException("No delegate servlet has been set"); | ||
| } | ||
| current.service(request, response); | ||
| if (request instanceof HttpServletRequest req && req.getMethod().equals("GET")) { | ||
| sseStreamEstablished.set(true); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be worth one extra line in the utility's comment: the observed signal is "a GET completed through |
||
| } | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -116,6 +128,10 @@ public void destroy() { | |
| this.delegate = null; | ||
| } | ||
|
|
||
| public boolean isStreamEstablished() { | ||
| return this.sseStreamEstablished.get(); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: 1s is tight next to the 5s awaits used elsewhere in this suite — on a loaded CI runner this could trade the
-32603flake for a "Failed to observe MCP Client connection" timeout. Would you consider aligning with the 5s convention (or a shared constant)? Non-blocking either way since the failure message would at least be clearer.