feat: OpenAPI and MCP from the same serve handlers (#20)
Tests / Test (push) Skipped
Tests / Release (semver) (push) Skipped
Tests / Test (push) Skipped
Tests / Release (semver) (push) Skipped
Agents get GET /openapi.json and POST /mcp. Tool names match search/get/stats/audit paths so PicoClaw does not need shebangs.
This commit is contained in:
committed by
GitHub
co-authored by
GitHub
parent
36976d9b53
commit
ff80359684
@@ -48,18 +48,22 @@ func NewServer(api API, workers int) http.Handler {
|
||||
|
||||
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.URL.Path {
|
||||
case "/health":
|
||||
case PathHealth:
|
||||
writeJSON(w, http.StatusOK, map[string]any{"status": "ok"})
|
||||
case "/search":
|
||||
case PathSearch:
|
||||
s.handleSearch(w, r)
|
||||
case "/get":
|
||||
case PathGet:
|
||||
s.handleGet(w, r)
|
||||
case "/stats":
|
||||
case PathStats:
|
||||
s.handleJSON(w, r, s.api.Stats)
|
||||
case "/audit":
|
||||
case PathAudit:
|
||||
s.handleJSON(w, r, s.api.Audit)
|
||||
case "/ingest":
|
||||
case PathIngest:
|
||||
s.handleJSON(w, r, s.api.Ingest)
|
||||
case PathOpenAPI:
|
||||
s.handleOpenAPI(w, r)
|
||||
case PathMCP:
|
||||
s.handleMCP(w, r)
|
||||
default:
|
||||
writeJSON(w, http.StatusNotFound, map[string]any{"error": "not found"})
|
||||
}
|
||||
@@ -112,6 +116,16 @@ func (s *Server) handleJSON(w http.ResponseWriter, r *http.Request, fn func(cont
|
||||
writeAPI(w, body, err)
|
||||
}
|
||||
|
||||
func (s *Server) tryAcquire(r *http.Request) bool {
|
||||
return s.acquire(nopWriter{}, r)
|
||||
}
|
||||
|
||||
type nopWriter struct{}
|
||||
|
||||
func (nopWriter) Header() http.Header { return http.Header{} }
|
||||
func (nopWriter) Write([]byte) (int, error) { return 0, nil }
|
||||
func (nopWriter) WriteHeader(int) {}
|
||||
|
||||
func (s *Server) acquire(w http.ResponseWriter, r *http.Request) bool {
|
||||
select {
|
||||
case s.semaphore <- struct{}{}:
|
||||
|
||||
Reference in New Issue
Block a user