Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 48 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,25 @@ Each account is fully isolated — its own aircraft, service timeline, flight lo

Aviary is also an MCP server, so an AI assistant can import your existing maintenance records — a spreadsheet, a typed list, another tracker's export — into your service timeline.

Add `https://aviary.danielibarra.com/mcp` as a remote (HTTP) MCP server in any assistant that supports MCP, then sign in when it asks.
The easiest way in is the **Import with AI** button on the dashboard — it shows the address with a Copy button and these same steps.

You sign in on Aviary's own login page and approve access; the assistant never sees your password. Then hand it your records and ask it to import them. It shows you a **proposal** first — the items it will add, anything it isn't sure about, and any rows it couldn't use and why. Nothing is added until you tell it to go ahead, and it never changes or deletes items you already have. See or disconnect assistants any time under the robot icon on the dashboard (**Connected assistants**).
**Connect (one time):**

1. In your AI assistant, add a **custom connector** (also called a **remote MCP server**).
2. Paste the address: `https://aviary.danielibarra.com/mcp`
3. When the assistant asks you to sign in, log in to Aviary and click **Allow**.

You sign in on Aviary's own login page; the assistant never sees your password. The assistant must support remote MCP servers with OAuth sign-in.

**Import:**

1. Give the assistant your records — paste a list or attach a spreadsheet — and ask it to import them into Aviary.
2. It shows you a **proposal** first: the items it will add, anything flagged for you to check (unclear dates, no due date, items you already have), and any rows it couldn't use and why.
3. Tell it to go ahead. The items are added to the bottom of your service timeline. Nothing is added before you confirm, and existing items are never changed or deleted.

Any row with a name can be imported — including on-condition items with no dates. Values that can't be used are left blank with a note.

**Disconnect:** open **Import with AI** on the dashboard; your connected assistants are listed with a **Disconnect** button, plus what each one imported. A disconnected assistant is cut off on its next request.

---

Expand Down Expand Up @@ -95,14 +111,43 @@ push to main
- **Production** (Heroku app `aviarist-d300b0c36379`, served at the link at the top) is a separate app, promoted from staging deliberately once it looks good.
- Heroku runs the app from the `Procfile` (`java -jar build/libs/AviaryService-0.0.1-SNAPSHOT.jar`) on Java 21 (`system.properties`). Schema changes apply via Hibernate `ddl-auto=update`.

## MCP server (developers)

`/mcp` is an [MCP](https://modelcontextprotocol.io) server (Spring AI, Streamable HTTP). Aviary is also its own OAuth 2.1 authorization server, so assistants sign in as an owner.

| | |
|---|---|
| Endpoint | `POST /mcp` — needs `Authorization: Bearer <token>`; without one you get `401` with `WWW-Authenticate: Bearer resource_metadata=…` |
| Discovery | `/.well-known/oauth-protected-resource`, `/.well-known/oauth-authorization-server` |
| Sign-in | Authorization code + PKCE (S256). Clients identify with a **Client ID Metadata Document** (an https `client_id` URL); Dynamic Client Registration is off |
| Tokens | Opaque, 7 days, stored SHA-256 hashed; checked against the database on every call, so Disconnect is immediate |
| Scopes | `aviary.read`, `aviary.timeline.import` |

**Tools** (each acts only on the signed-in owner's data):

| Tool | What it does |
|---|---|
| `get_import_format` | Item fields, rules, and an example |
| `list_service_timeline` | The owner's current items |
| `propose_timeline_import` | Validates items into a proposal (24 h); changes nothing |
| `continue_poor_fit` | Continues a proposal where most rows didn't fit, after the owner agrees |
| `confirm_timeline_import` | Adds exactly the proposal's items, all or nothing |
| `list_flights` | The owner's logged flights |

**Config:** `aviary.oauth.issuer` (env `AVIARY_OAUTH_ISSUER`) is the site's public URL; the MCP address is that plus `/mcp`. It defaults to `http://localhost:8080` locally and `https://aviary.danielibarra.com` on Heroku — set it on staging to the staging URL, or sign-in there points at production.

**Try it locally:** run `./gradlew bootRun`, then add `http://localhost:8080/mcp` as a remote MCP server in an MCP client (or use the [MCP Inspector](https://github.com/modelcontextprotocol/inspector)) and sign in with a seeded account.

## Architecture

The app is a small, conventional Spring MVC project under `src/main/java/com/example/AviaryService/`:

- **`controllers/UserController.java`** — every route: auth pages, the dashboard, timeline CRUD + reordering, hours updates, flight-log CRUD, the Garmin CSV parser, and "Complete Maintenance."
- **`entity/`** — `User`, `ServiceTimeline`, `FlightLog`, `DescriptionOption` (+ a `DTO/` for timeline updates).
- **`repositories/`** — Spring Data JPA repositories, all scoped by user.
- **`config/`** — `SecurityConfig` (login/logout, BCrypt, per-route access) and `DataSeeder` (the H2 demo data).
- **`config/`** — `SecurityConfig` (login/logout, BCrypt, per-route access, the `/mcp` bearer-token chain) and `DataSeeder` (the H2 demo data).
- **`oauth/`** — the OAuth authorization server for MCP sign-in (client metadata documents, hashed token storage, token checks).
- **`mcp/`** — MCP tools; **`services/imports/`** + **`util/TimelineImportRules`** — import proposals, confirm, and the Import with AI page's connections.
- **`resources/templates/`** + **`resources/static/`** — Thymeleaf views and the dashboard's CSS/JS.

Deeper design docs live in **[docs/](docs/)** — see `ARCHITECTURE.md`, `BACKEND.md`, `FRONTEND.md`, `DATABASE.md`, and `BUILD_AND_DEPLOY.md`. A **Share/Export** feature (print / PDF / email / text) is specced in `docs/specs/SHARE_EXPORT_SPEC.md` but not yet built.
4 changes: 4 additions & 0 deletions docs/architecture/FRONTEND.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ Each stylesheet defines the same CSS-variable palette (`--primary` green `#2C9B6
- Log Book rows are readonly — to fix a typo a user must delete + re-add (a known deferred improvement).
- Login/register field + button labels are injected via CSS `::before` pseudo-elements, which is fragile and not screen-reader friendly.
- No frontend tests exist.

## Import with AI page
- `GET /account/connections` (`connections.html`): titled "Import with AI". An always-visible connect box shows this site's MCP address (`mcpUrl` = `aviary.oauth.issuer` + `/mcp`, so staging shows staging's), a Copy button (`js/connections.js`, falls back to selecting the address), three steps, the per-assistant "where to find it" list (`fragments/assistant-hints.html` — one line per assistant, update there when an app moves its menu), and what to do next. The connected-assistant list and recent imports sit below under "Connected assistants".
- Dashboard entry points: header `#connections-link` (robot icon + "Import with AI"; text hidden under 420px, `aria-label` kept) and `#import-ai-prompt` above the empty Service Timeline (server-rendered only when there are no rows; `dashboard.js` removes it via a MutationObserver when the first row is added). Both are `no-print`.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;

import java.time.Instant;
import java.util.List;
import java.util.UUID;

import org.junit.jupiter.api.Test;
Expand All @@ -14,9 +15,9 @@
import com.example.AviaryService.repositories.TimelineImportRecordRepository;

/**
* Account -> Connected assistants: a connected assistant is listed, the
* dashboard links to the page, and Disconnect removes it -- at desktop and
* phone widths.
* Import with AI page: the connect box (address, Copy, steps, hints) is always
* shown; a connected assistant is listed with its imports, and Disconnect
* removes it -- at desktop and phone widths.
*/
class ConnectionsPageTest extends BrowserTestBase {

Expand Down Expand Up @@ -55,6 +56,7 @@ private void listAndDisconnect(int width, int height) {
page.locator("#connections-link").click();
page.waitForURL(baseUrl() + "/account/connections");

assertThat(page.locator("#connect-box")).isVisible();
assertThat(page.locator(".connection-name")).hasText("Test Assistant");
assertThat(page.locator(".connection-meta")).containsText("assistant.example.com");
assertThat(page.locator(".connection-imports")).containsText("added 3 items");
Expand All @@ -68,7 +70,49 @@ private void listAndDisconnect(int width, int height) {
page.locator("button.connection-disconnect").click();
page.waitForURL("**/account/connections?disconnected");
assertThat(page.locator(".connection")).hasCount(0);
assertThat(page.locator("body")).containsText("No AI assistants are connected");
assertThat(page.locator("body")).containsText("No assistants connected yet");
assertThat(page.locator("#connect-box")).isVisible();
}

private void assertNoSidewaysScroll(int width) {
Object overflow = page.evaluate("document.documentElement.scrollWidth > window.innerWidth");
if (Boolean.TRUE.equals(overflow)) {
throw new AssertionError("Import with AI page scrolls horizontally at " + width + "px");
}
}

@Test
void connectBoxShowsWithNoConnections() {
page.setViewportSize(390, 844);
String username = seedUser("password123");
loginAs(username, "password123");
page.navigate(baseUrl() + "/account/connections");

assertThat(page.locator("h1")).hasText("Import with AI");
assertThat(page.locator("#connect-box")).isVisible();
String address = page.locator("#mcp-url").inputValue();
if (!address.endsWith("/mcp")) throw new AssertionError("Unexpected address: " + address);
assertThat(page.locator("#connect-steps li")).hasCount(3);
if (page.locator("#assistant-hints li").count() < 1) throw new AssertionError("No assistant hints");
assertThat(page.locator("#connect-next")).containsText("preview");
assertThat(page.locator("body")).containsText("No assistants connected yet");
assertNoSidewaysScroll(390);
}

@Test
void copyButtonCopiesTheAddress() {
context.grantPermissions(List.of("clipboard-read", "clipboard-write"), new com.microsoft.playwright.BrowserContext.GrantPermissionsOptions().setOrigin(baseUrl()));
String username = seedUser("password123");
loginAs(username, "password123");
page.navigate(baseUrl() + "/account/connections");

String address = page.locator("#mcp-url").inputValue();
page.locator("#copy-mcp-url").click();
assertThat(page.locator("#copy-mcp-url")).hasText("Copied");
Object clipboard = page.evaluate("navigator.clipboard.readText()");
if (!address.equals(clipboard)) {
throw new AssertionError("Clipboard has '" + clipboard + "', expected '" + address + "'");
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package com.example.AviaryService.browser;

import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

import com.example.AviaryService.entity.ServiceTimeline;
import com.example.AviaryService.repositories.ServiceTimelineRepository;
import com.microsoft.playwright.options.LoadState;

/**
* Ways into the Import with AI page from the dashboard: the labeled header
* control (text on desktop, named icon on a phone) and the prompt shown only
* while the service timeline is empty.
*/
class ImportWithAiEntryTest extends BrowserTestBase {

@Autowired
ServiceTimelineRepository timelineRepository;

private void assertNoSidewaysScroll(int width) {
Object overflow = page.evaluate("document.documentElement.scrollWidth > window.innerWidth");
if (Boolean.TRUE.equals(overflow)) {
throw new AssertionError("Dashboard scrolls horizontally at " + width + "px");
}
}

// ---- header control (US2) ----

@Test
void headerShowsLabeledControlOnDesktop() {
page.setViewportSize(1280, 800);
loginAs(seedUser("password123"), "password123");

assertThat(page.locator("#connections-link")).containsText("Import with AI");
assertThat(page.locator("#connections-link .connections-link-text")).isVisible();
page.locator("#connections-link").click();
page.waitForURL(baseUrl() + "/account/connections");
}

@Test
void headerShowsNamedIconOnPhone() {
page.setViewportSize(390, 844);
loginAs(seedUser("password123"), "password123");
page.waitForLoadState(LoadState.NETWORKIDLE);

assertThat(page.locator("#connections-link")).isVisible();
assertThat(page.locator("#connections-link")).hasAttribute("aria-label", "Import with AI");
assertNoSidewaysScroll(390);
}

// ---- empty-timeline prompt (US3) ----

@Test
void emptyTimelineShowsPrompt() {
page.setViewportSize(1280, 800);
loginAs(seedUser("password123"), "password123");

assertThat(page.locator("#import-ai-prompt")).isVisible();
page.locator("#import-ai-prompt a").click();
page.waitForURL(baseUrl() + "/account/connections");
}

@Test
void neitherControlPrints() {
page.setViewportSize(1280, 800);
loginAs(seedUser("password123"), "password123");
page.emulateMedia(new com.microsoft.playwright.Page.EmulateMediaOptions()
.setMedia(com.microsoft.playwright.options.Media.PRINT));
assertThat(page.locator("#import-ai-prompt")).isHidden();
assertThat(page.locator("#connections-link")).isHidden();
}

@Test
void timelineWithItemsHasNoPrompt() {
page.setViewportSize(1280, 800);
String username = seedUser("password123");
ServiceTimeline t = new ServiceTimeline();
t.setUser(userRepository.findByUsername(username));
t.setItem("Annual");
t.setTimelineOrder(0);
timelineRepository.save(t);
loginAs(username, "password123");

assertThat(page.locator("#import-ai-prompt")).hasCount(0);
}

@Test
void addingFirstRowRemovesPromptWithoutReload() {
page.setViewportSize(1280, 800);
loginAs(seedUser("password123"), "password123");
page.waitForLoadState(LoadState.NETWORKIDLE);
assertThat(page.locator("#import-ai-prompt")).isVisible();

page.locator(".add-row td[data-label='Item'] textarea").fill("Oil change");
page.locator("td.add-cell form button.add-button").click();

assertThat(page.locator(".sortable tr[data-id]")).hasCount(1);
assertThat(page.locator("#import-ai-prompt")).hasCount(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Map;
import java.util.NoSuchElementException;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
Expand All @@ -21,20 +22,25 @@
import com.example.AviaryService.repositories.UserRepository;
import com.example.AviaryService.services.imports.ConnectionService;

// Account -> Connected assistants: the AI assistants signed in to this
// owner's account, with a Disconnect button for each.
// Import with AI: how to connect an AI assistant (this site's MCP address and
// steps), then the assistants signed in to this owner's account, each with a
// Disconnect button.
@Controller
public class ConnectionsController {

private final ConnectionService connectionService;
private final UserRepository userRepository;
private final TimelineImportRecordRepository importRecordRepository;
// This site's MCP address -- production, staging, and local each show their own.
private final String mcpUrl;

public ConnectionsController(ConnectionService connectionService, UserRepository userRepository,
TimelineImportRecordRepository importRecordRepository) {
TimelineImportRecordRepository importRecordRepository,
@Value("${aviary.oauth.issuer}") String issuer) {
this.connectionService = connectionService;
this.userRepository = userRepository;
this.importRecordRepository = importRecordRepository;
this.mcpUrl = issuer + "/mcp";
}

@GetMapping("/account/connections")
Expand All @@ -49,6 +55,7 @@ public String connections(Principal principal, Model model) {
}
}
model.addAttribute("imports", imports);
model.addAttribute("mcpUrl", mcpUrl);
return "connections";
}

Expand Down
82 changes: 82 additions & 0 deletions src/main/resources/static/css/connectionsstyle.css
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,85 @@
.connections-back {
color: var(--primary-dark);
}

/* Import with AI: connect box */
#connect-box {
display: flex;
flex-direction: column;
gap: 12px;
padding: 16px;
border: 1px solid var(--border);
border-radius: var(--radius);
background: var(--primary-light);
}

.connect-address {
display: flex;
gap: 8px;
}

#mcp-url {
flex: 1;
min-width: 0;
padding: 10px;
border: 1px solid var(--border);
border-radius: var(--radius);
font: inherit;
font-size: 0.9rem;
background: var(--surface);
color: var(--text);
}

#copy-mcp-url {
flex-shrink: 0;
padding: 10px 14px;
border: 1px solid var(--primary);
border-radius: var(--radius);
background: var(--primary);
color: #fff;
font: inherit;
font-weight: 600;
cursor: pointer;
}

#copy-mcp-url:hover {
background: var(--primary-dark);
}

#connect-steps {
padding-left: 20px;
display: flex;
flex-direction: column;
gap: 4px;
}

.assistant-hints-title {
font-weight: 600;
font-size: 0.9rem;
}

#assistant-hints {
padding-left: 20px;
color: var(--text-muted);
font-size: 0.85rem;
overflow-wrap: anywhere;
}

#assistant-hints code {
font-size: 0.8rem;
}

#connect-next {
font-size: 0.9rem;
}

.connections-heading {
font-size: 1.05rem;
margin-top: 8px;
}

@media (max-width: 420px) {
.connect-address {
flex-direction: column;
}
}
Loading
Loading