# getBunServer

**Kind:** Function

**Source:** [`src/adapter/bun/server.ts`](https://github.com/honojs/hono/blob/main/src/adapter/bun/server.ts#L13)

**Part of:** [Adapter](subsystem-src-adapter)

Get Bun Server Object from Context

`getBunServer` reads the Bun `Server` instance from a request context created by the Bun adapter. Use it inside route handlers when server-level Bun APIs are needed alongside normal Hono context methods.

## Signature

```ts
function getBunServer(c: Context): T | undefined
```

## Parameters

| Name | Type |
|---|---|
| `c` | `Context` |

**Returns:** `T | undefined`

## Diagram

```mermaid
graph LR
  BunServer[Bun Server] --> BunAdapter[Bun adapter serve()]
  BunAdapter --> Context[Hono Context]
  Context --> GetServer[getBunServer]
  GetServer --> ServerApi[Bun Server APIs]
```

## Usage

```ts
import { Hono } from 'hono'
import { getBunServer, serve } from 'hono/bun'

const app = new Hono()

app.get('/server', (c) => {
  const server = getBunServer(c)

  return c.json({
    hostname: server.hostname,
    port: server.port,
  })
})

serve({
  fetch: app.fetch,
})
```

## AI Coding Instructions

- Call `getBunServer(c)` from handlers that receive a Hono `Context`.
- Run the application through the Bun adapter so the active server is available on the context.
- Keep Bun-specific server operations in Bun adapter routes or modules.
- Do not use this function in handlers shared with non-Bun adapters.

## Used by

2 references from 2 files. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

### Imported by (2)

- `getConnInfo` — `src/adapter/bun/conninfo.ts`:10
- `BunServerWebSocket` — `src/adapter/bun/websocket.ts`:8
