-
-
Notifications
You must be signed in to change notification settings - Fork 967
docs(server-core): add README with package overview and usage example #1331
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
Open
nuthalapativarun
wants to merge
2
commits into
VoltAgent:main
Choose a base branch
from
nuthalapativarun:docs/1330-server-core-readme-worktree
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@voltagent/server-core": patch | ||
| --- | ||
|
|
||
| Add README documentation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| <div align="center"> | ||
| <a href="https://voltagent.dev/"> | ||
| <img width="1500" height="276" alt="voltagent" src="https://github.com/user-attachments/assets/d9ad69bd-b905-42a3-81af-99a0581348c0" /> | ||
| </a> | ||
|
|
||
| <h3 align="center"> | ||
| AI Agent Engineering Platform | ||
| </h3> | ||
|
|
||
| <div align="center"> | ||
| <a href="https://voltagent.dev">Home Page</a> | | ||
| <a href="https://voltagent.dev/docs/">Documentation</a> | | ||
| <a href="https://github.com/voltagent/voltagent/tree/main/examples">Examples</a> | ||
| </div> | ||
| </div> | ||
|
|
||
| <br/> | ||
|
|
||
| <div align="center"> | ||
|
|
||
| [](https://github.com/voltagent/voltagent/issues) | ||
| [](https://github.com/voltagent/voltagent/pulls) | ||
| [](https://opensource.org/licenses/MIT) | ||
| [](https://www.npmjs.com/package/@voltagent/server-core) | ||
| [](https://www.npmjs.com/package/@voltagent/server-core) | ||
| [](https://s.voltagent.dev/discord) | ||
|
|
||
| </div> | ||
|
|
||
| ## @voltagent/server-core | ||
|
|
||
| Framework-agnostic server core for VoltAgent. This package provides the shared infrastructure — route definitions, request handlers, WebSocket support, authentication utilities, MCP/A2A protocol helpers, and a base server provider — that all VoltAgent server adapters (e.g. `@voltagent/server-hono`) build on top of. | ||
|
|
||
| You typically do not use this package directly. Instead, choose a server adapter for your framework (such as `@voltagent/server-hono`) and pass it to the `VoltAgent` constructor. If you are building a **custom server adapter**, this package gives you everything you need. | ||
|
|
||
| --- | ||
|
|
||
| ## Key Exports | ||
|
|
||
| ### Base Server Provider | ||
|
|
||
| `BaseServerProvider` — Abstract class that handles the common server lifecycle (port allocation, WebSocket setup, graceful shutdown, startup banner). Extend it when building a custom adapter. | ||
|
|
||
| ```ts | ||
| import { BaseServerProvider } from "@voltagent/server-core"; | ||
| ``` | ||
|
|
||
| ### Route Definitions | ||
|
|
||
| Pre-built, framework-agnostic route metadata objects you can use to register routes in any HTTP framework: | ||
|
|
||
| | Export | Routes covered | | ||
| | ----------------------------- | -------------------------------------------- | | ||
| | `AGENT_ROUTES` | Agent management and generation | | ||
| | `WORKFLOW_ROUTES` | Workflow execute / stream / suspend / resume | | ||
| | `TOOL_ROUTES` | Tool listing and direct execution | | ||
| | `MEMORY_ROUTES` | Conversation and message management | | ||
| | `LOG_ROUTES` | Log retrieval | | ||
| | `OBSERVABILITY_ROUTES` | Traces, spans, and observability status | | ||
| | `OBSERVABILITY_MEMORY_ROUTES` | Memory inspection for observability | | ||
| | `MCP_ROUTES` | Model Context Protocol server endpoints | | ||
| | `A2A_ROUTES` | Agent-to-Agent protocol endpoints | | ||
| | `ALL_ROUTES` | All of the above combined | | ||
|
|
||
| Helper functions: `getAllRoutesArray()`, `getRoutesByTag(tag)`. | ||
|
|
||
| ### Request Handlers | ||
|
|
||
| Framework-agnostic handler functions. Each handler receives a `ServerProviderDeps` context and returns a serialisable response object, making them easy to wrap in any HTTP framework: | ||
|
|
||
| - **Agent handlers** — `handleGenerateText`, `handleStreamText`, `handleChatStream`, `handleResumeChatStream`, `handleGenerateObject`, `handleStreamObject` | ||
| - **Workflow handlers** — `handleGetWorkflows`, `handleGetWorkflow`, `handleExecuteWorkflow`, `handleStreamWorkflow`, `handleAttachWorkflowStream`, `handleSuspendWorkflow`, `handleResumeWorkflow`, `handleListWorkflowRuns`, `handleGetWorkflowState` | ||
| - **Tool handlers** — `handleListTools`, `handleExecuteTool` | ||
| - **Memory handlers** — `handleListMemoryConversations`, `handleCreateMemoryConversation`, `handleSaveMemoryMessages`, and more | ||
| - **Observability handlers** — `getTracesHandler`, `getTraceByIdHandler`, `getObservabilityStatusHandler`, and more | ||
| - **Log handlers** — `handleGetLogs` | ||
|
|
||
| ### Authentication | ||
|
|
||
| Plug-in auth via the `AuthProvider` interface. A built-in JWT provider is included: | ||
|
|
||
| ```ts | ||
| import { jwtAuth, createJWT } from "@voltagent/server-core"; | ||
| ``` | ||
|
|
||
| ### WebSocket Utilities | ||
|
|
||
| `createWebSocketServer`, `setupWebSocketUpgrade` — set up real-time log and observability streaming over WebSocket. | ||
|
|
||
| ### MCP & A2A Protocol Helpers | ||
|
|
||
| - `MCPServerRegistry`, `listMcpServers`, `lookupMcpServer` — register and resolve MCP servers | ||
| - `A2AServerRegistry`, `listA2AServers`, `lookupA2AServer`, `executeA2ARequest` — Agent-to-Agent protocol support | ||
|
|
||
| ### App Setup Utilities | ||
|
|
||
| `getOpenApiDoc`, `shouldEnableSwaggerUI`, `getOrCreateLogger`, `DEFAULT_CORS_OPTIONS` — helpers shared by all server adapters. | ||
|
|
||
| ### Edge Entry Point | ||
|
|
||
| A lighter entry point for edge runtimes (e.g. Cloudflare Workers, Vercel Edge) is available at the `./edge` export: | ||
|
|
||
| ```ts | ||
| import { AGENT_ROUTES, handleGenerateText } from "@voltagent/server-core/edge"; | ||
| ``` | ||
|
|
||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| --- | ||
|
|
||
| ## Usage Example — Custom Server Adapter | ||
|
|
||
| The snippet below shows the minimum required to build a custom server adapter on top of `@voltagent/server-core`: | ||
|
|
||
| ```typescript | ||
| import { createServer, type Server } from "node:http"; | ||
| import { BaseServerProvider, type ServerProviderConfig } from "@voltagent/server-core"; | ||
| import type { ServerProviderDeps } from "@voltagent/core"; | ||
|
|
||
| export class MyCustomServerProvider extends BaseServerProvider { | ||
| constructor(deps: ServerProviderDeps, config: ServerProviderConfig = {}) { | ||
| super(deps, config); | ||
| } | ||
|
|
||
| protected async startServer(port: number): Promise<Server> { | ||
| const server = createServer((req, res) => { | ||
| // Route incoming requests to the framework-agnostic handlers | ||
| res.writeHead(404); | ||
| res.end("Not found"); | ||
| }); | ||
|
|
||
| await new Promise<void>((resolve) => server.listen(port, resolve)); | ||
| return server; | ||
| } | ||
|
|
||
| protected async stopServer(): Promise<void> { | ||
| await new Promise<void>((resolve, reject) => { | ||
| this.server?.close((err) => (err ? reject(err) : resolve())); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| // Factory function consumed by VoltAgent | ||
| export function myCustomServer(config?: ServerProviderConfig) { | ||
| return (deps: ServerProviderDeps) => new MyCustomServerProvider(deps, config); | ||
| } | ||
| ``` | ||
|
|
||
| Pass the factory to `VoltAgent`: | ||
|
|
||
| ```typescript | ||
| import { VoltAgent, Agent } from "@voltagent/core"; | ||
| import { openai } from "@ai-sdk/openai"; | ||
| import { myCustomServer } from "./my-custom-server"; | ||
|
|
||
| const agent = new Agent({ | ||
| name: "my-agent", | ||
| instructions: "A helpful assistant", | ||
| model: openai("gpt-4o-mini"), | ||
| }); | ||
|
|
||
| new VoltAgent({ | ||
| agents: { agent }, | ||
| server: myCustomServer({ port: 3141 }), | ||
| }); | ||
| ``` | ||
|
|
||
| For a complete, production-ready server adapter see [`@voltagent/server-hono`](https://github.com/VoltAgent/voltagent/tree/main/packages/server-hono). | ||
|
|
||
| --- | ||
|
|
||
| ## Documentation | ||
|
|
||
| - [VoltAgent Documentation](https://voltagent.dev/docs/) | ||
| - [Agent Overview](https://voltagent.dev/docs/agents/overview/) | ||
| - [MCP Integration](https://voltagent.dev/docs/agents/mcp/) | ||
|
|
||
| ## License | ||
|
|
||
| Licensed under the MIT License, Copyright © 2026-present VoltAgent. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.